Hi,
I'm trying to write a code for square using function. However I get the error when I declare the function prototype outside (similar to what I do for int functions), While It works fine when I declare the float function prototype inside main. Why it differ from int function? and Do I need to write prototype in every function where I need to call Square.
Working Code:
Code:
#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
int main( )
{
float square(float x) ;
float a, b ;
printf ( "\nEnter any number " ) ;
scanf ( "%f", &a ) ;
b = square ( a ) ;
printf ( "\nSquare of %f is %f", a, b ) ;
}
float square ( float x )
{
float y ;
y = x * x ;
return ( y ) ;
}
Code Not working (With prototype outside main)
Code:
#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
int main( )
float square(float x) ;
{
float a, b ;
printf ( "\nEnter any number " ) ;
scanf ( "%f", &a ) ;
b = square ( a ) ;
printf ( "\nSquare of %f is %f", a, b ) ;
}
float square ( float x )
{
float y ;
y = x * x ;
return ( y ) ;
}