Ask Question
10 July, 19:14

Write a program that prints, line by line, the numbers from 1 to 100. For multiples of three print the word "Cow" instead of the number and for the multiples of seven print "Pie" instead of the number. For numbers which are multiples of both three and seven print "CowPie''

+1
Answers (1)
  1. 10 July, 19:41
    0
    Condition 1: Print whole numbers from 1 to 100 line by line

    Condition 2: All multiples of 3 should be printed as Cow

    Condition 3: All multiples of 7 should be printed as Pie

    Condition 4: All multiples of 3 and 7 should be printed as CowPie

    //Program starts here.

    / / Program is written in C++

    / / Comments are used for explanatory purpose

    #include

    using namespace std;

    int main ()

    {

    / / Iterate a counter from 1 to 100

    for (int i = 1; i<=100; i++)

    {

    //Test for Multiples of 3

    if (i%3 = = 0 && i%7! = 0)

    {

    cout<<"Cow"<
    }

    //Test for Multiples of 7

    else f (i%3! = 0 && i%7 = = 0)

    {

    cout<<"Pie"<
    }

    / / Test for Multiples of 3 and 7

    else if (i%3 = = 0 && i%7 = = 0)

    {

    cout<<"CowPie"<
    }

    //Other numbers

    else

    {

    cout<
    }

    }

    return 0;

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a program that prints, line by line, the numbers from 1 to 100. For multiples of three print the word "Cow" instead of the number and ...” in 📘 Engineering 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