1#include<stdio.h>
2int main(){
3 int i,f=1,num;
4
5 printf("Enter a number: ");
6 scanf("%d",&num);
7
8 for(i=1;i<=num;i++)
9 f=f*i;
10
11 printf("Factorial of %d is: %d",num,f);
12 return 0;
13}
1//Factorial of a given number
2#include <stdio.h>
3
4//This function returns factorial of the number passed to it
5long int factorialOf(int number){
6 long int factorial = 1;
7 while(number){
8 factorial*=number;
9 number-=1;
10 }
11 return factorial;
12}
13
14int main(void) {
15 int n;
16 printf("Find factorial of \n");
17 scanf("%d",&n);
18 printf("\nThe factorial of %d is %ld",n,factorialOf(n));
19 return 0;
20}
1#include <stdio.h>
2
3int fact(int);
4
5void main()
6{
7 int no,factorial;
8
9 printf("Enter a number to calculate it's factorial\n");
10 scanf("%d",&no);
11 factorial=fact(no);
12 printf("Factorial of the num(%d) = %d\n",no,factorial);
13//printf("Factorial of the num(%d) = %d\n",no,fact(no));//another way of calling a function//comment above two lines if you want to use this
14}
15
16int fact(int n)
17{
18 int i,f=1;
19 for(i=1;i<=n;i++)
20 {
21 f=f*i;
22 }
23 return f;
24}
25
1#include <stdio.h>
2
3int fact (num1);
4
5void main ()
6{
7 int num,ret;
8
9 printf ("Enter the number: ");
10 scanf("%d",&num);
11
12 ret = fact(num);
13
14 printf("\nthe factorial of %d is %d\n",num,ret);
15
16}
17
18int fact(num1)
19{
20 int i, f=1;
21
22 for(i=1; i<=num1; i++)
23 {
24 f = f * i;
25 }
26
27 return f;
28}
29