Ask Question
4 October, 23:57

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) :

+2
Answers (1)
  1. 5 October, 03:47
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers