Q2. Print even numbers using a loop
Print even numbers in a loop until some given limit
From this solution notice how to declare function prototype declarations before you can use the functions in your programs
/* printevens.cpp */ #include <iostream> using namespace std; void printevens(int limit); //function prototype declaration int main() { //call the printevens() function printevens(100); cin.get(); return 0; } void printevens(int limit) { for (int i = 1; i <= limit ; i++) if(i % 2 == 0) cout << i << "\t"; }
page revision: 4, last edited: 06 Sep 2009 19:47