Tech Blog » Home » Coders Forum » Computer Directory » Math Calculators » RSS:Directory|Forum
C++ » Source Code » C++ Links » for Loops » File Streams » Switch » Coders Community: Forum
// - Show all odd numbers using a for loop #include <iostream> using namespace std; int main() { for (int count = 1; count <= 41; count += 2) { cout << count << ", "; } cout << endl; return 0; } /*==================[output]================================================= 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, Press any key to continue . . . =============================================================================*/
// - Count backwards using a for loop. #include <iostream> using namespace std; int main() { for (int count = 15; count > -1; count--) { cout << count << ", "; } cout << endl; return 0; } /*=================[output]========================== 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, Press any key to continue . . . =====================================================*/
// - Count by fives using a for loop. #include <iostream> using namespace std; int main() { for (int count = 0; count <= 100; count += 5) { cout << count << ", "; } cout << endl; return 0; } /*=====================[output]================================================== 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100, Press any key to continue . . . =================================================================================*/