Question

Using a while loop, write a program that reads 10 integer numbers. The program shall count...

Using a while loop, write a program that reads 10 integer numbers. The program shall count how many of them are multiples of 2, how many are multiples of 3, and how many are NOT multiples of either 2 or 3. The output should be similar to the one shown below.

c++ language

Homework Answers

Answer #1

CODE IS PROVIDED WITH COMMENTS

CODE:

#include <iostream>
using namespace std;

int main() {
    int x[10];    //declaring an array
    int i;
    int count1=0;    //declaring and initialzing the variables
    int count2=0;
    int count3=0;
    
    cout<<"enter the 10 elements\n"<<endl;
    for(i=0;i<10;i++)
    {
         
        cin>>x[i];           //inputting the array elements
    }
    int j=0;
    while(j<10)              //while lopp to check whether multiple or not
    {
         if(x[j]%2==0)        //condition to be a multiple of 2
         {   
             count1=count1+1;    //increasing the count for each multiple of 2
             
            
         }
         if(x[j]%3==0)        //condition to be a multiple of 3
         {
             count2=count2+1;          //increasing the count for each multiple of 3
         }
         if((x[j]%2 != 0) & (x[j]%3 != 0))    //condition for a value to be not a multiple of either 2 or 3
         {
             count3=count3 + 1;                //increasing the count for every true value
         }
        j=j+1;                                  //increasing the j value 
    }
    cout<<"there are "<<count1<<" multiples of 2\n";            //printing the count of the multiples of 2
    cout<<"there are "<<count2<<" multiples of 3\n";            //printing the count of multiples of 3
    cout<<"there are "<<count3<<" numbers which are not multiples of either 2 or 3";  
    
        return 0;
}

INPUT & OUTPUT:
CODE (screen shot):


Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Step 2 Exercise - Using while loop:    Write a Java program (using while loop) to display...
Step 2 Exercise - Using while loop:    Write a Java program (using while loop) to display 5 lines of smiley faces. The following would be the output of your program: Note: Sample program is in the "Important Documents", Module 6 folder) Hello:                          Bye!
Write a program that reads three integer values from the keyboard using the Scanner class representing,...
Write a program that reads three integer values from the keyboard using the Scanner class representing, respectively, a number of quarters, dimes, and nickels. Convert the total coin amount to dollars and output the result.Write a program that reads three integer values from the keyboard using the Scanner class representing, respectively, a number of quarters, dimes, and nickels. Convert the total coin amount to dollars and output the result.
Use C++ Write a program that first reads in how many whole numbers the user wants...
Use C++ Write a program that first reads in how many whole numbers the user wants to sum, then reads in that many whole numbers, and finally outputs the sum of all the numbers greater than zero, the sum of all the numbers less than zero (which will be a negative number or zero), and the sum of all the numbers, whether positive, negative, or zero. The user enters the numbers just once each and the user can enter them...
Write spim program and execute it on mars. Your program reads two integer values x and...
Write spim program and execute it on mars. Your program reads two integer values x and y. Write a function called sum that gets x and y passed as parameters and return the sum of odd values between x and y inclusive. In addition write another function called even that gets x and y as parameters and returns the count of all even numbers between x and y inclusive. Also in main print the quotient and remainder of diving y...
Write a program to input a sequence of 8 integers, count all the odd numbers and...
Write a program to input a sequence of 8 integers, count all the odd numbers and sum all the negative integers. One integer is input and processed each time around the loop. Python Programming
Problem 2: Write a program that reads an integer and displays, using asterisks, a filled diamond...
Problem 2: Write a program that reads an integer and displays, using asterisks, a filled diamond of the given side length. For example, if the side length is 5, the program should display c++ look like a diamond
Write a program that reads an integer, a list of words, and a character. The integer...
Write a program that reads an integer, a list of words, and a character. The integer signifies how many words are in the list. The output of the program is every word in the list that contains the character at least once. Assume at least one word in the list will contain the given character. Assume that the list of words will always contain fewer than 20 words. Ex: If the input is: 4 hello zoo sleep drizzle z then...
Uses a while loop to print the numbers from 3 - 19. Uses a do-while loop...
Uses a while loop to print the numbers from 3 - 19. Uses a do-while loop to print the numbers from 42 - 56. Uses a for loop to print the numbers from 87 - 95. Asks the user for 2 numbers. Uses a loop to print all numbers between the given numbers, inclusive. Note: Consider that your user's second number can be lower! (see example below) Note: Also consider that your user might give you two of the same...
In JAVA: Write a program that reads an integer, a list of words, and a character....
In JAVA: Write a program that reads an integer, a list of words, and a character. The integer signifies how many words are in the list. The output of the program is every word in the list that contains the character at least once. Assume at least one word in the list will contain the given character. Assume that the list of words will always contain fewer than 20 words. Ex: If the input is: 4 hello zoo sleep drizzle...
1) Write a java programming using a while loop where you will add numbers and when...
1) Write a java programming using a while loop where you will add numbers and when you press number 0 it will add all your numbers and display the results. Use Scanner object. Steps: 1) Declare variables integer called sum which is equal to zero   2) Declare Scanner object   3) Declare while condition where is true   4) Inside of that condition prompt the user to enter the numbers   5) Declare variable integer called number and input the number statement   6)...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT