CODE IN C:
#include <stdio.h>
int main()
{
int n;
printf("Enter the value of n : ");
scanf("%d",&n);
int fac=1; //initially factorial is taken to be 1
for(int i=1;i<=n;i++)//for loop
{
fac=fac*i;//calculating factorial value
}
printf("The value of fac using for loop is : %d",fac);
printf("\n");
int fac2=1;//initially factorial is taken to be 1
int i=1;
while(i<=n) //while loop
{
fac2=fac2*i;
i++;
}
printf("The value of fac using while loop is : %d",fac2);
}
OUTPUT SNIPPET:
Please give an upvote if you liked my solution.
Thank you :)
Get Answers For Free
Most questions answered within 1 hours.