Question

In: Computer Science

Write a C++ code using while loop which is getting the two integers from the user,...

Write a C++ code using while loop which is getting the two integers from the user, and output how many numbers are multiples of 5, and how many numbers are multiples of 7 between the two integers (inclusive).

Solutions

Expert Solution

C++ code:

#include <iostream>
using namespace std;
int main(){
    //initializing limits n1 and n2
    int n1,n2;
    //asking for them
    cout<<"Enter limits: ";
    //accepting them
    cin>>n1>>n2;
    //initializing i and count
    int i=n1,count5=0,count7=0;
    //looping till n2
    while(i<=n2){
        //checking if divisible by 7
        if(i%7==0)
        //incrementing count7
            count7++;
        //checking if divisible by 5
        if(i%5==0)
        //incrementing count5
            count5++;
        //incrementing i
        i++;
    }
    //printing Count5
    cout<<"Count of number divivsible by 5: "<<count5<<endl;
    //printing Count7
    cout<<"Count of number divivsible by 7: "<<count7<<endl;
    return 0;
}

Screenshot:


Input and Output:


Related Solutions

every code should be in java Program 1: Write a while loop that sums the integers...
every code should be in java Program 1: Write a while loop that sums the integers from 1 to 10, excluding 3 and 6. Print the sum. [Hint: Use logical operators] Program 2: Write a for loop that attempts to display the numbers from 1 to 10, but terminates when the control variable reaches the value 6. Program 3: Write a do...while loop that prints the integers from 10 to 0, inclusive.
Write a program in PYTHON, using a while loop, that asks the user to enter the...
Write a program in PYTHON, using a while loop, that asks the user to enter the amount that they have budgeted for the month. The program should then prompt the user to enter their expenses for the month. The program should keep a running total. Once the user has finished entering their expenses the program should then display if the user is over or under budget. The output should display the monthly budget, the total expenses and whether the user...
Write a Java program using using WHILE loop to find the sum of all integers between...
Write a Java program using using WHILE loop to find the sum of all integers between 200 to 250 which are divisible by 7. Sample Output: Numbers between 200 and 250, divisible by 7: 203 210 217 224 231 238 245 The sum is: 1568
Using a while loop. Write a JAVA program that asks a user for an integer between...
Using a while loop. Write a JAVA program that asks a user for an integer between 1 and 9. Using the user input, print out the Fibonaccci series that contains that number of terms. Sample output: How many terms would like printed out for the Fibonacci Sequence? 7 Fibonacci Series of 7 numbers: 0 1 1 2 3 5 8
C++ while loop Exercise Write a program that continues to ask the user to enter any...
C++ while loop Exercise Write a program that continues to ask the user to enter any set of numbers, until the user enters the number -1. Then display the total sum of numbers entered and their average. (note that you need to define a counter that counts how many numbers so the average = (sum/n) where n is your counter total. #include <iostream> using namespace std; int main() { int number, n=0, sum=0; cout << "Enter a number to start...
Write a program that uses a while statement to read integers from the user and prints...
Write a program that uses a while statement to read integers from the user and prints the sum, average, and largest of these numbers. The input should terminate if the user enters 999. The average should be output with 4 digits of precision. c++ please ASAP
Write a python code which prints triangle of stars using a loop ( for loop )...
Write a python code which prints triangle of stars using a loop ( for loop ) Remember what 5 * "*" does The number of lines of output should be determined by the user. For example, if the user enters 3, your output should be: * ** *** If the user enters 6, the output should be: * ** *** **** ***** ****** You do NOT need to check for valid input in this program. You may assume the user...
C++ please 1. Write a do while loop that continually loops until the user enters a...
C++ please 1. Write a do while loop that continually loops until the user enters a single digit between 0 and 9. There should only be one prompt for the user to enter a number inside the loop. 2. Write a simple 4 function calculator using a switch statement. The program should switch on the operator: +, -, *, /. The user should enter two numbers (any type is fine) and then enter an operator and the program should perform...
Write a do-while loop IN JAVA to build a Pokémon game Prompt the user for two...
Write a do-while loop IN JAVA to build a Pokémon game Prompt the user for two names one for their Pokémon, and one for the computers Pokémon Make two integer variables to hold the HP of each Pokémon, HP should be 20 for both Pokémon’s. Use Math.random() to determine the amount of damage caused, and which move the computer will select. The range of damage that can be done is up to you. Output to the user an attack menu...
Important: please use python. Using while loop, write python code to print the times table (from...
Important: please use python. Using while loop, write python code to print the times table (from 0 to 20, incremented by 2) for number 5. Add asterisks (****) so the output looks exactly as shown below.   Please send the code and the output of the program. ****************************************************************** This Program Shows Times Table for Number 5 (from 0 to 20) Incremented by 2 * ****************************************************************** 0 x 5 = 0 2 x 5 = 10 4 x 5 = 20 6...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT