+ 1
Write a program that reads an integer consisting of three numbers and then prints the number of the digits, the number of tens,
5 Answers
+ 11
In C++:
int x = 0;
cin >> x;
cout << x/100 << endl; //hundreds
cout << (x/10)%10 << endl; //tens
cout << x%10 << endl; //units
+ 9
Which language?
+ 2
thanks so much
+ 2
#include <math.h>
#include <iostream>
int findSize(int num)
{
sum = 0;
while(num/=10)
{
sum+=1;
}
return sum;
}
int main()
{
int x = 0;
cin >> x;
int size = findSize(x);
for(auto i = size-1; i>=0; i++)
{
cout << (x/pow(10, i))%10;
}
}
or something like that, but that's the idea. and you can try to optimize this of course.
+ 1
in c++ language