Pages

Factorial program in c using for loop

Wednesday, 6 March 2013
#include <stdio.h>

int main()
{
               int a, n;
               int fact = 1;

               printf("Enter a number to calculate it's factorial\n");
               scanf("%d", &n);

               for (a = 1; a <= n; a++)
                     fact = fact * a;
               printf("Factorial of %d = %d\n", n, fact);
               return 0;
}

No comments:

Post a Comment