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).
#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;
}
Comments
Leave a comment