Ask Question
19 May, 18:49

Write a C+ + program to find all numbersless than 1000 which are:

1) Divisible by 7?

2) Divisible by 11?

3) Divisible by 7 but not divisible by 11?

4) Divisible by both 7 and 11?

5) Notdivisible by 7 or 11?.

+2
Answers (1)
  1. 19 May, 20:13
    0
    The c+ + program is shown below.

    #include

    using namespace std;

    int main () {

    cout<<"Numbers less than 1000 which are divisible by 7"<
    for (int k=1; k<1000; k++)

    {

    / / number should give remainder 0 which show complete divisibility

    if (k%7 = = 0)

    cout<
    }

    cout<
    for (int k=1; k<1000; k++)

    {

    if (k%11 = = 0)

    cout<
    }

    cout<
    for (int k=1; k<1000; k++)

    {

    / / for 11, number should not give remainder 0 which shows incomplete divisibility

    if (k%7 = = 0 && k%11! = 0)

    cout<
    }

    cout<
    for (int k=1; k<1000; k++)

    {

    if (k%7 = = 0 && k%11 = = 0)

    cout<
    }

    cout<
    for (int k=1; k<1000; k++)

    {

    if (k%7! = 0 && k%11! = 0)

    cout<
    }

    return 0;

    }

    Explanation:

    The test for divisibility is done by using the modulus operator which is used as a condition inside the if statement. This test is done inside for loop.

    All the numbers from 1 to 999, less than 1000, are divided by 7 and / or 11 depending on the sub question. Only the numbers which are completely divisible are displayed. Divisible numbers give remainder 0 always.

    The divisibility test by 7 is shown below.

    cout<<"Numbers less than 1000 divisible by 7"<
    for (int k=1; k<1000; k++)

    {

    if (k%7 = = 0)

    cout<
    }

    In other words, all the numbers divisible by 7 are same as the numbers in the table of 7.

    The same logic shown above is applied for other sub questions to test for divisibility by 11 and combination of 7 and 11.

    To improve readability, tabs and new lines are inserted at appropriate places.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a C+ + program to find all numbersless than 1000 which are: 1) Divisible by 7? 2) Divisible by 11? 3) Divisible by 7 but not ...” 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