22. write a C program to find the factorial of a number using functions


Program to find the factorial of a number using functions 

Source Code:

#include<stdio.h>
void function(int number)
{
int i,fact=1;
i=1;
while(i<=number)
{
fact=fact*i;
i++;
}
printf("factorial of %d is:%d",number,fact);
}
int main()
int n;
printf("Enter n Value:\n");
scanf("%d",&n);
function(n);
return 0;

}

Output:

Enter n Value:
7
factorial of 7 is:5040

No comments:

Post a Comment