0
It's interesting to know how this code is working...?
#include <stdio.h> //int rec(int x);// to remove warning please un-comment this int main() { int a=5,fact; fact=rec(a); printf ("Factorial value = %d", fact); return 0; } int rec(x) //how this line is working? int x; { int f; if(x == 1) return (1); else f=x*rec (x-1); return (f); } https://code.sololearn.com/cTG4wwyR4aBh/?ref=app https://code.sololearn.com/cTG4wwyR4aBh/?ref=app
2 Answers
+ 4
The syntax is an ancient way of declaring a function.
int rec(x)
int x;
{
...
}
is equivalent to
int rec(int x)
{
...
}
+ 2
Definition of function "rec()" should write before main() function, if You don't want to write function Prototype [ i.e. int rec(int x); ].
And Run It.
Then You will get Output without Warnings.