Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Tara
- Jan 17th 2017
- Lab 1
- */
- #include <stdio.h>
- #include <stdbool.h>
- int summation();
- int choice;
- int main()
- {
- int num;
- 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: ");
- scanf("%d", choice);
- if (choice == 1){
- summation();
- }
- return 0;
- }
- int summation()
- {
- bool validNum = false;
- int num = 0, i, sum=0;
- while (!validNum){
- printf("Enter a number (>= 1): ");
- scanf("%d", &num);
- if (num <= 0){
- printf("Invalid Number.\n");
- }
- else if (num>0){
- validNum = true;
- }
- }
- for(i=0; i <= num; i++)
- {
- sum += i;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement