Advertisement
kamandos

HomeWork

Jul 15th, 2022
780
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.44 KB | None | 0 0
  1. #include <stdio.h>
  2. int main() {
  3.     int n, i;
  4.     unsigned long long fact = 1;
  5.     printf("Enter an integer: ");
  6.     scanf("%d", &n);
  7.  
  8.     // shows error if the user enters a negative integer
  9.     if (n < 0)
  10.         printf("Error! Factorial of a negative number doesn't exist.");
  11.     else {
  12.         for (i = 1; i <= n; ++i) {
  13.             fact *= i;
  14.         }
  15.         printf("Factorial of %d = %llu", n, fact);
  16.     }
  17.  
  18.     return 0;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement