Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. /*
  2. Tara
  3. Jan 17th 2017
  4. Lab 1
  5. */
  6.  
  7. #include <stdio.h>
  8. #include <stdbool.h>
  9.  
  10. int summation();
  11. int choice;
  12.  
  13. int main()
  14. {
  15. int num;
  16. printf("***Choose a function to use!***\n Enter 1 for summation\n Enter 2 for factorial\n Enter 3 for fibonacci\n Enter 4 for greatest common denominator\n Enter 5 for a power function: ");
  17. scanf("%d", choice);
  18. if (choice == 1){
  19. summation();
  20.  
  21. }
  22. return 0;
  23. }
  24.  
  25. int summation()
  26. {
  27. bool validNum = false;
  28. int num = 0, i, sum=0;
  29.  
  30. while (!validNum){
  31.  
  32. printf("Enter a number (>= 1): ");
  33. scanf("%d", &num);
  34.  
  35. if (num <= 0){
  36. printf("Invalid Number.\n");
  37. }
  38. else if (num>0){
  39. validNum = true;
  40.  
  41. }
  42. }
  43.  
  44. for(i=0; i <= num; i++)
  45. {
  46. sum += i;
  47. }
  48. return 0;
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement