Question-Write a function to calculate the factorial value of any integer
entered through the keyboard.
Solution-
functions are the most beautiful thing i've seen in C. They provide clearness in programs. let's check out the solution of this problem.
#include<stdio.h>
int main()
{
int n;
printf("Enter any potter\n");
scanf("%d",&n);
factorial(n);
return 0;
}
factorial(int n)
{
int fact=1,i;
for(i=n;i>=1;i--)
fact=fact*i;
printf("Factorial value=%d\n",fact);
}
entered through the keyboard.
Solution-
functions are the most beautiful thing i've seen in C. They provide clearness in programs. let's check out the solution of this problem.
#include<stdio.h>
int main()
{
int n;
printf("Enter any potter\n");
scanf("%d",&n);
factorial(n);
return 0;
}
factorial(int n)
{
int fact=1,i;
for(i=n;i>=1;i--)
fact=fact*i;
printf("Factorial value=%d\n",fact);
}
No comments:
Post a Comment