Ask Question
8 October, 16:40

Write a for loop that will print the values 1 to 20 while skipping the odd numbers (2,4,6,8,10,12,14,16,18,20) :

+5
Answers (1)
  1. 8 October, 17:03
    0
    void main ()

    {

    int counter;

    cout<<""Even numbers between 1 to 20 are:""<
    //Method 1

    for (counter = 1; counter < = 20; counter++)

    {

    if (counter%2 = = 0)

    {

    cout<
    }

    }

    //Method 2 - simplest one

    for (counter = 2; counter < = 20; )

    {

    cout<
    counter = counter + 2;

    }

    return 0;

    }

    Explanation:

    In this, Method 1 runs a for loop and check whether each number is divided by 2. If yes, then printed otherwise it is skipped.

    In the second method, it runs for loop only for even numbers. This is obtained by incrementing the counter by 2.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a for loop that will print the values 1 to 20 while skipping the odd numbers (2,4,6,8,10,12,14,16,18,20) : ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers