Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Chris Hinds
- // CSC 150
- // assignment 8
- // 10/24/14
- #include <stdio.h>
- int main (void)
- {
- int S;
- int E;
- int I;
- //------------------------------
- //Problem 1a:Display the numbers from 1 to 10 using a while loop.
- //------------------------------
- S=1;
- puts("Problem 1a: Numbers 1 - 10 using a while loop:");
- while(S <= 10)
- { printf("%i..\n", S); ++S;}
- puts("End of problem 1a.");
- //------------------------------
- //Problem 1b:Display the numbers from 1 to 10 using a for loop
- //------------------------------
- puts("Problem 1b: Numbers 1 - 10 using a for loop:");
- for(S=1; S<=10; ++S)
- {printf("%i..\n", S);}
- puts("End of problem 1b");
- //------------------------------
- //Problem 2a. User input and count down to 1.
- //------------------------------
- puts("Problem 2a: User inputs a number and it counts down to 0, using a while loop.");
- printf("Please input a whole number greater than 1:");
- scanf("%i", &S);
- E=S;
- while(E>=1)
- {printf("%i..\n", E); E--;}
- puts("End of problem 2a");
- //-----------------------------
- //Problem 2b.
- //-----------------------------
- puts("Problem 2b. Program takes user input and does the same process using a for loop.");
- printf("Please input a whole number greater than 1:");
- scanf("%i,", &S);
- for(S;S>=1;S--)
- {printf("%i..\n" ,S);}
- puts("End of problem 2b.");
- //------------------------------
- //Problem 3a
- //------------------------------
- puts("Finally. Here we are at the end. Problem 3a lets the user pick the first, last, and increment by numbers.");
- printf("Please choose your starting number, ending number, and how much the program should count up by, separated by a comma:");
- scanf("%i, %i, %i,", &S, &E, &I);
- puts("Using a while loop:");
- while(S<=E)
- {printf("%i..", S); S=S+I;}
- puts("End of problem 3a.");
- //------------------------------
- //Problem 3b
- //-----------------------------
- puts("Problem 3b accomplishes the same task, using a for loop, which is much easier, whenever that damned while loop wants to retire.");
- for(S;S<=E;S=(S+I))
- {printf("%i..\n", S);}
- puts("End of problem 3b.");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement