Advertisement
yoyo106

Factorial

Apr 23rd, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.41 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. void main()
  5. {
  6.     while (1)
  7.     {
  8.      int n,i,product=1;
  9.     printf("Enter value: ");
  10.     scanf("%d",&n);
  11.     if (n>0)
  12.     {
  13.         for (i=n;i>0;i--)
  14.         {
  15.             product*=i;
  16.         }
  17.         printf("Factorial = %d\n",product);
  18.     }
  19.     else if (n==0)
  20.         printf("Factorial = 1\n");
  21.     else
  22.         printf("Undefined value\n");
  23.     }
  24.  
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement