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";
}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License