Rajesh Kumar Sahoo
e-mail: sahoorajesh.d@gmail.com
mobile: +91-9853493896
e-mail: sahoorajesh.d@gmail.com
mobile: +91-9853493896
#include<stdio.h>
int fact(int num){
if((num == 0)||(num == 1))
return 1;
else
return num*fact(num-1);
}
int main(int argc, char *argv[]){
int num;
num = atoi(argv[1]);
printf("%d!=%d\n",num,fact(num));
return 0;
}
rajesh@ThinkPad:~/Rajesh/blogs$ gcc factorial.c -o factnum
rajesh@ThinkPad:~/Rajesh/blogs$ ./factnum 4
4!=24
rajesh@ThinkPad:~/Rajesh/blogs$ ./factnum 5
5!=120
rajesh@ThinkPad:~/Rajesh/blogs$ ./factnum 6
6!=720
#include<stdio.h>
int fact(int num){
int res;
res=1;
while(num){
res*=num;
num--;
}
return res;
}
int main(int argc, char *argv[]){
int num;
num = atoi(argv[1]);
printf("%d!=%d\n",num,fact(num));
return 0;
}
rajesh@ThinkPad:~/Rajesh/blogs$ gcc factorial.c -o factnum
rajesh@ThinkPad:~/Rajesh/blogs$ ./factnum 4
4!=24
rajesh@ThinkPad:~/Rajesh/blogs$ ./factnum 5
5!=120
rajesh@ThinkPad:~/Rajesh/blogs$ ./factnum 6
6!=720