Advertisement
Neo_Feo

Horor_CPP5_Done

Sep 17th, 2023
972
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.55 KB | Source Code | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int factorial(short num){
  5.     int isNegativ = 0, result = 1;
  6.     if(num == 0)
  7.         return 1;
  8.     if(num<0){
  9.         isNegativ = 1;
  10.         num*=-1;
  11.     }
  12.  
  13.     for(int i = 1; i <= num; ++i)
  14.         result *= i;
  15.  
  16.     return  isNegativ ? result*-1 : result;
  17. }
  18.  
  19. int main()
  20. {
  21.     int num;
  22.     printf("introduceti numarul al carui factorial doriti sa-l aflati: ");
  23.     scanf("%i",&num);
  24.     printf("factorialul numarului %d este %d",num,factorial(num));
  25.     //printf("g=%d",factorial(-4));
  26.     return 0;
  27. }
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement