wrote:
> Hi All,
>
> I want to know how many times 'Hi' will prints; and why?
>
>
> #include<stdio.h>
>
> int fact( int n );
>
> main() {
>
> int f;
>
> f = fact( 4 );
>
> printf("\nfact = %d", f);
> }
>
> int fact( int n ) {
> int fa;
>
> if ( n == 0 ) return 1;
>
> fa = n * fact( n - 1 );
>
> printf("\nHi");
>
> return fa;
> }
>
Better write it like this:
#include <stdio.h>
int fact(int n);
int main(void) {
int f;
f = fact(4);
printf("\nfact = %d\n", f);
return 0;
}
int fact(int n) {
int fa;
if (n==0) return 1;
fa = n*fact(n-1);
printf("\nHi");
return fa;
}
1) Declared main() as int main(void) and
2) added a '\n' to the last printf() to ensure that everything will be
printed.
You can now run the algorithm in piece of paper...
--
one's freedom stops where others' begin
Giannis Papadopoulos
Computer and Communications Engineering dept. (CCED)
University of Thessaly
http://dop.freegr.net/