Nop your wrong. Every code is executed sequentialy! so when you want 10!, you first need 9! for which you call the factr function again, but 9! also needs 8! which calls the function.

Recursion is a function call made by the same function itself.

Which compiler are you using. Debug your code and enter the factr function, keep steping into to see what hapenning

Here's some examples

Code:

int pow10(int n){
return n==0 ?1 : 10*pow10(n-1);
}

Code:

int display_string(const char* s){//returns number of printed chars
if(*s == 0 ) return 0;
putchar(*s );
return 1+string(s+1);
}

Code:

void print_this_n_times(int n){
if(n==0){
printf("I'm inside the function but n is zero.... bye\n");
}else{
printf("I'm inside the function and I'm going to call myself because n is %d\n",n);
print_this_n_times(n-1);
printf(" function ended\n",n);
}
}

Originally Posted by

**Lionmane**
This is the output I'm getting:

/*

Type '0' to quit.

Please specify a max range to calculate factorials.

10

Calculating factorial of 10

Calculating factorial of 9

Calculating factorial of 8

Calculating factorial of 7

Calculating factorial of 6

Calculating factorial of 5

Calculating factorial of 4

Calculating factorial of 3

Calculating factorial of 2

Calculating factorial of 1

2 2

3 6

4 24

5 120

6 720

7 5040

8 40320

9 362880

10 3628800

*/

Not to mention how does it start from the largest number and calculate backwards if the larger result depends on the smaller results?

Read your statement and look at the results.