Ask Question
26 May, 21:10

Write a program which promptsuser to enter an integer value. Using while loop print the valuesfrom

zero up to the number enteredby the user.

• Enlist the odd numbers out of them

• Enlist the prime numbers out of odd number list and printtheir sum (add all the prime numbers)

+4
Answers (1)
  1. 26 May, 22:51
    0
    Answer:Following is the c+ + code for the problem:

    #include

    using namespace std;

    int main () {

    int number;

    cout<<"Enter the number"<
    cin>>number;

    int i=0, c=0, odd[500];

    while (i<=number) / /loop for printing the numbers form 0 to number.

    {

    cout<
    if (i%2!=0) / / storing in the odd array if the number is odd.

    {

    odd[c++]=i; //storing odd numbers ...

    }

    i++;

    }

    cout<
    i=0;

    cout<<"The odd numbers are "<
    while (i
    {

    cout<
    i++;

    }

    cout<
    i=0;

    int sum=0;

    while (i
    {

    int div=2;

    while (div
    {

    if (odd[i]%div==0)

    break;

    div++;

    }

    if (div==odd[i])

    {

    cout<
    sum+=odd[i]; //updating the sum ...

    }

    i++;

    }

    cout<
    return 0;

    }

    Output:

    Enter the number

    49

    0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49

    The odd numbers are

    1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49

    The prime numbers are

    3 5 7 11 13 17 19 23 29 31 37 41 43 47

    The sum of odd prime numbers is 326.

    Explanation:

    First I have printed the values from 0 to n and i have taken an array to store odd numbers. After that i have printed the odd values. And after that i have printed prime numbers among the odd numbers and their sum. These all operations are done using while loop.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a program which promptsuser to enter an integer value. Using while loop print the valuesfrom zero up to the number enteredby the ...” 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