Write a function called printEvens that prints all the even numbers between 2 and 20, inclusive. It will take no arguments and return nothing. You must also use a looping statement in the code to get credit for printing (i.e. no cout << 2 << " " << 4 " " << ...).

Respuesta :

Answer:

#include <iostream>

using namespace std;

void printEvens() {

   for (int i = 2; i <= 20; i++) {

       if (i % 2 == 0)

           cout << i << " ";

   }

}

int main() {

   printEvens();

   return 0;

}

Explanation:

- Inside the function, initialize a for loop that goes from 2 to 20.

- Inside the for loop, check if the numbers are divisible by 2. If yes, print the number

- Inside the main, call the function