Advertisement
apl-mhd

factorial

Sep 4th, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.31 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4.  
  5. // factorial
  6.  
  7. int fact(int n){
  8.   double factValue = 1;
  9.  
  10.     int i;
  11.  
  12.     for(i =1; i<=n; i++){
  13.  
  14.         factValue = factValue * i;
  15.     }
  16.  
  17.  
  18. return factValue;
  19. }
  20.  
  21. int main()
  22. {
  23.  
  24.     int n;
  25.     scanf("%d",&n);
  26.  
  27.     printf("%d\n", fact(n));
  28.  
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement