Hello again :) This time I'm back with a stranger question. The following program is meant to factorialize (spelling?) a number from the command line while printing out the number of calls it made to the function "factorial".
#include <stdio.h>
#include <stdlib.h>
unsigned long long factorial(int num,int *count_ptr){
printf("Call %u\n",*count_ptr);
*count_ptr=(*count_ptr)+(1);
if (num==0)
return (1);
num=num * (factorial(num-1,count_ptr));
return (num);
}
int main(int arg_num, char *argv[]){
int num=atoi(argv[1]);
unsigned long long output;
int count=0;
int *count_ptr;
count_ptr=&count;
output=num*factorial(num-1,count_ptr);
printf("%llu \n",output);
return 0;
}
This code is very similar to a friend of mine's but for some reason it doesn't seem to be correct for anything greater than 13. Everything works fine, including the number of calls it makes. Except for the result... I thought there was an overflow somewhere but unsigned long long didn't fix it :(