#include%26lt;stdio.h%26gt;
main()
{
float a,b;
printf("Enter any number");
scanf("\n %f",%26amp;a);
b=square(a);
printf("\n square of %f is %f",a,b);
}
square(float x)
{
float y;
y=x*x;
return(y);
system("pause");
}
I have compiled below c pgam in dev c++.i am getting the error.what may be the prob?plz clarify.?
You're missing includes.
math.h
Reply:try this coding:there's no error in this
#include%26lt;stdio.h%26gt;
#include%26lt;windows.h%26gt;
#include%26lt;conio.h%26gt;
//function declaration
float square(float x);
void main()
{
float a,b;
printf("Enter any number\n");
scanf("\n%f",%26amp;a);
b=square(a);
printf("\n square of %f is %f",a,b);
}
//function definition
float square(float x)
{
float y;
y=x*x;
return(y);
system("pause");
}
Reply:several people use system("PAUSE") when they want to delay their programs. but it's a bad habit.
by calling system(), you are invoking the default shell. the shell then executes the commandline given to it ("PAUSE", in this case). that is, it runs the 'pause.exe' program. so, now your simple c program is relying on two external programs for a stupid thing like pressing a single key. what if someone deleted or renamed 'pause.exe'? what if someone tried to compile your program on unix, or a mac? it wouldn't work. you'd get an annoying shell message and no pause.
Reply:what error? dev c++ is very descriptive
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment