Advertisement
Sierra_ONE

Factorial

Sep 17th, 2023 (edited)
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.31 KB | Source Code | 0 0
  1. #include <stdio.h>
  2.  
  3. int main(void){
  4.  
  5.     int num;
  6.     long factorial = 1;
  7.  
  8.     printf("Enter a number: ");
  9.     scanf("%d", &num);
  10.  
  11.     long orignum = num;
  12.  
  13.     while (num > 1){
  14.  
  15.         factorial *= num;
  16.  
  17.         num -= 1;
  18.     }
  19.  
  20.     printf("Factorial of %d is %ld", orignum, factorial);
  21.  
  22.  
  23.     return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement