I've writtin a program in C to calculate the n!(n factorial) but I am obviously doing somthing wrong because I keep getting errors and I think it has something to do with the z=n; and if statements. Please help...
#include<stdio.h>
main()
{
int n; /*n is the number entered by the user*/
int i; /*i is the counter*/
scanf("%d",&n);
printf("Enter a positive integer:\n\n");
z=n; /*z is the result after the first loop is ran*/
for(i=n; i>0; i--)
{
if(n=0)
z=1;
z=z*i;
}
printf("The factorial of %d is:%d",n,z);
}
Bookmarks