Advertisement
Guest User

Untitled

a guest
Nov 11th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. long factorial(int);
  4.  
  5. long factorial(int two){
  6. int three;
  7. long result = 1;
  8. for (three =1; three <= two; three++)
  9. result = result*three;
  10. return result;
  11. }
  12.  
  13.  
  14.  
  15. int main(int argc, char **argv){
  16. int one;
  17. int two;
  18. int three;
  19. printf("Please enter the number of rows you wish to see in the pascal triangle\n");
  20. scanf("%d",&two);
  21.  
  22. if (two > 20 || two < 1){
  23. printf("The value entered must be between 1 and 20 exclusively.");
  24. return 1;
  25. }
  26. for (one = 0; one < two; one++)
  27. {
  28. for (three = 0; three <= (two - one - 2); three++)
  29. printf(" ");
  30. for (three = 0; three <= one; three++)
  31. printf("%ld", factorial(one)/(factorial(three)*factorial(one-three)));
  32.  
  33. printf("\n");
  34.  
  35.  
  36. }
  37.  
  38. return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement