Advertisement
Gargit

Loops Exercises Part 4.1

Jul 31st, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. Exercise 4.1:
  2. Using a for loop to iterate backward, print the values 100 to 0.
  3. - Modify the for loop to include 0 and include 100
  4.  
  5. #include <iostream>
  6.  
  7. void main()
  8. {
  9. int i = 100;
  10.  
  11. while (i >= 0)
  12. {
  13. std::cout << i << std::endl;
  14. i--;
  15. }
  16.  
  17. system("pause");
  18. }
  19.  
  20.  
  21. - Modify the for loop to include 0 and not 100
  22.  
  23. #include <iostream>
  24.  
  25. #include <iostream>
  26.  
  27. void main()
  28. {
  29. int i = 99;
  30.  
  31. while (i >= 0)
  32. {
  33. std::cout << i << std::endl;
  34. i--;
  35. }
  36.  
  37. system("pause");
  38. }
  39.  
  40. - Modify the for loop to not include 0 and include 100
  41.  
  42. #include <iostream>
  43.  
  44. #include <iostream>
  45.  
  46. void main()
  47. {
  48. int i = 100;
  49.  
  50. while (i > 0)
  51. {
  52. std::cout << i << std::endl;
  53. i--;
  54. }
  55.  
  56. system("pause");
  57. }
  58.  
  59. - Modify the for loop to decrement by 2
  60.  
  61. #include <iostream>
  62.  
  63. void main()
  64. {
  65. int i = 100;
  66.  
  67. while (i > 0)
  68. {
  69. std::cout << i << std::endl;
  70. i-=2;
  71. }
  72.  
  73. system("pause");
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement