Answer to Question #294159 in C++ for Jon

Question #294159

Write a program using integers userNum and x as input, and output userNum divided by x three times. 

Ex: If the input is:

2000 2

the output is: 

1000 500 250

Note: In C++, integer division discards fractions. Ex: 6 / 4 is 1 (the 0.5 is discarded).




1
Expert's answer
2022-02-05T06:01:18-0500
#include <iostream>


int main()
{
    int userNum=0, x = 0;


    std::cout << "Enter userNum : ";
    std::cin >> userNum;
    std::cout << "Enter x : ";
    std::cin >> x;


    for (int i = 0; i < 3; i++)
    {
        userNum /= x;
        std::cout << userNum << " ";
    }
    std::cout << std::endl;
     
    system("pause");
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog