Ask Question
9 May, 06:25

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''

+3
Answers (1)
  1. 9 May, 06:47
    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 the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers