Calculating
Source Code for Calculating Factorial of a Number using a For Loop in C Programming
Following is the source code for calculating the factorial of a number using a For Loop in C Programming.
Source Code for Calculating Factorial of a Number using a DO WHILE Loop in C Programming
Following is the source code for calculating the factorial of a number using a DO WHILE Loop in C Programming.
main()
{
int a,b,i;
printf("Enter a number between 0 and 33: ");
scanf("%d",&i);
b=1;
a=1;
if(i>=1)
do
{ b*=a;
a++;
}while(a<=i);
printf("%d\n",b);
}
Source Code for Calculating Factorial of a Number using a Recursive Function in C Programming
Following is the source code for calculating the factorial of a number using a Recursive Function in C Programming.
int f(int n)
{
if (n==0)
return 1;
if (n>0)
return n*f(n-1);
}
main()
{
int n;
printf("Enter a number between 0 and 33: ");
scanf("%d",&n);
printf("%d\n",f(n));
}
Source Code for Calculating Factorial of a Number using a WHILE Loop in C Programming
Following is the source code for calculating the factorial of a number using a WHILE Loop in C Programming.
main()
{
int a,b;
printf("Enter a number between 0 and 33: ");
scanf("%d",&a);
b=1;
while(a>=1)
{ b*=a;
a--;
}
printf("%d\n",b);
}
