Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Exercise 4.1:
- Using a for loop to iterate backward, print the values 100 to 0.
- - Modify the for loop to include 0 and include 100
- #include <iostream>
- void main()
- {
- int i = 100;
- while (i >= 0)
- {
- std::cout << i << std::endl;
- i--;
- }
- system("pause");
- }
- - Modify the for loop to include 0 and not 100
- #include <iostream>
- #include <iostream>
- void main()
- {
- int i = 99;
- while (i >= 0)
- {
- std::cout << i << std::endl;
- i--;
- }
- system("pause");
- }
- - Modify the for loop to not include 0 and include 100
- #include <iostream>
- #include <iostream>
- void main()
- {
- int i = 100;
- while (i > 0)
- {
- std::cout << i << std::endl;
- i--;
- }
- system("pause");
- }
- - Modify the for loop to decrement by 2
- #include <iostream>
- void main()
- {
- int i = 100;
- while (i > 0)
- {
- std::cout << i << std::endl;
- i-=2;
- }
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement