how to find factorial of any number using c language ?

Today we are learn how to find factorial of any number using c language first we know about factorial I know everyone know about that but we are going with very basic, so let's know about factorial first then go througth the code.

Factorial is number which is multiple of all his previous number upto 1. 

for example..

Factorial of 5 which give

5*4*3*2*1=120

Similary factorial of 7

7*6*5*4*3*2*1=5040

Now I hope you understand the concept of factorial



So now we are write our program to find factorial of any number basically we use ‘for’ loop to perform this program

Let’s start……

SOURCE CODE:-


#include<stdio.h>
int main(){
    int a,n,sum=1;
    printf("enter the value of n=");
    scanf("%d",&n);
    for(a=1;a<=n;a++){
        sum=sum*a;
    }
    printf("factorial of %d is %d",n,sum);
    return 0;
}

OUTPUT:-

enter the value of n=8
factorial of 8 is 40320




0 Comments