pages

Wednesday, 9 June 2021

c-program to find the factorial of the number using function | c-programming languages

Program to find the factorial of the number

In this program we will now find the factorial of the number by taking input form the number using function in c-programming.
 factorial of 5 is = 1*2*3*4*5= 120






#include<stdio.h>
#include<conio.h>
int factorial(int);
void main()
{
         int x,fact;
         printf("enter the number:-");
         scanf("%d",&x);
         fact=factorial(x);
         printf("\n the factorial of the number is %d",fact);
         getch();
}
int factorial(int a)
{
         int f=1,i;
         for(i=1;i<=a;i++){
                  f=f*i;
         }
         return(f);
}

output:-










No comments:

Post a Comment