/*program to find the factorial of a given number*/
#include<stdio.h>
main()
{
int fact(int );
/*-----------------------------------------------------*/
int n,fact;
printf("\nenter the number for which you want to find the factorial");
scanf("%d",&n);
fact=fact(n);
printf("\nthe factorial of yhe number %d is %d",n,fact);
}
/*-----------------------------------------------------*/
int fact(int n)
{
if(n==1) return(1);
else return n*fact(n-1);
}
Damn! I didn't realise this thread was started 4 friggin' years ago.
Thanks a lot ##k.k## - why did you "revive" a thread from 4 years ago that had been answered?
- and void main is still bad!
Sheesh
Last edited by yellowSnow; Aug 1st, 2009 at 6:01 pm. Reason: pissed off
/****************C Program for factorial by using recursion**************/
#include<stdio.h>
int fact(int a);
int facto(int s) //this function will calculate by recursive
{
if((s==0)||(s==1))
return 1;
else
return(s*facto(s-1));
}
main()
{ int n,result,result1;
printf("Pls enter ur num\n");
scanf("%d",&n);
result=facto(n);
result1=fact(n);
printf("facto of ur num= %d\n fact of ur num =%d\n",result,result1);
}
/***************************function for factorial without recursive*************/
int fact(int a)
{ int i,c=1;
for(i=1;i<=a;i++)
c=c*i;
return(c);
}
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.