Advertisement
christhizzi

blah to the blah

Oct 24th, 2014
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.35 KB | None | 0 0
  1. // Chris Hinds
  2. // CSC 150
  3. // assignment 8
  4. // 10/24/14
  5.  
  6. #include <stdio.h>
  7. int main (void)
  8. {
  9.         int S;
  10.         int E;
  11.         int I;
  12.  
  13. //------------------------------
  14. //Problem 1a:Display the numbers from 1 to 10 using a while loop.
  15. //------------------------------
  16.         S=1;
  17.         puts("Problem 1a: Numbers 1 - 10 using a while loop:");
  18.         while(S <= 10)
  19.         { printf("%i..\n", S); ++S;}
  20.         puts("End of problem 1a.");
  21.  
  22. //------------------------------
  23. //Problem 1b:Display the numbers from 1 to 10 using a for loop
  24. //------------------------------
  25.  
  26.         puts("Problem 1b: Numbers 1 - 10 using a for loop:");
  27.         for(S=1; S<=10; ++S)
  28.         {printf("%i..\n", S);}
  29.         puts("End of problem 1b");
  30.  
  31. //------------------------------
  32. //Problem 2a.  User input and count down to 1.
  33. //------------------------------
  34.  
  35.         puts("Problem 2a: User inputs a number and it counts down to 0, using a while loop.");
  36.         printf("Please input a whole number greater than 1:");
  37.         scanf("%i", &S);
  38.         E=S;
  39.         while(E>=1)
  40.         {printf("%i..\n", E); E--;}
  41.         puts("End of problem 2a");
  42.  
  43. //-----------------------------
  44. //Problem 2b.
  45. //-----------------------------
  46.  
  47.         puts("Problem 2b.  Program takes user input and does the same process using a for loop.");
  48.         printf("Please input a whole number greater than 1:");
  49.         scanf("%i,", &S);
  50.         for(S;S>=1;S--)
  51.         {printf("%i..\n" ,S);}
  52.         puts("End of problem 2b.");
  53.  
  54. //------------------------------
  55. //Problem 3a
  56. //------------------------------
  57.  
  58.         puts("Finally.  Here we are at the end.  Problem 3a lets the user pick the first, last, and increment by numbers.");
  59.         printf("Please choose your starting number, ending number, and how much the program should count up by, separated by a comma:");
  60.     scanf("%i, %i, %i,", &S, &E, &I);
  61.         puts("Using a while loop:");
  62.         while(S<=E)
  63.         {printf("%i..", S); S=S+I;}
  64.         puts("End of problem 3a.");
  65.  
  66. //------------------------------
  67. //Problem 3b
  68. //-----------------------------
  69.  
  70.         puts("Problem 3b accomplishes the same task, using a for loop, which is much easier, whenever that damned while loop wants to retire.");
  71.         for(S;S<=E;S=(S+I))
  72.         {printf("%i..\n", S);}
  73.         puts("End of problem 3b.");
  74.  
  75. return 0;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement