Calculating Factorial of a number in C-programming
In this post you will gonna learn how to calculate factorial of a number in C-programming.
In this method we will print the factorial of a number using for loop.This is one of the simple method of calculating the factorial of a number.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n,fact=1,c;
printf("Enter a number");
scanf("%d",&n);
for(c=1;c<=n;c++)
{
fact=fact*c;
}
printf("The factorial of the number is %d",fact);
return 0;
}
In this method we will print the factorial of a number using for loop.This is one of the simple method of calculating the factorial of a number.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n,fact=1,c;
printf("Enter a number");
scanf("%d",&n);
for(c=1;c<=n;c++)
{
fact=fact*c;
}
printf("The factorial of the number is %d",fact);
return 0;
}
I have also attatched a screenshot of my programme in codeblocks.This might help you more.
Comments
Post a Comment