0

IN CPP, How to get a 2 digit number from user and output it on 2 sperate lines?

Like get the number 32 and output it like 3 2 Is it even possible?

31st May 2023, 10:33 AM
Faran Allah Verdi
Faran Allah Verdi - avatar
6 Answers
+ 2
//Method 1 #include <iostream> using namespace std; int main() { int num = 32; cout << num/10 <<endl; cout << num%10 << endl; }
1st Jun 2023, 7:10 AM
Cool-Coder
Cool-Coder - avatar
+ 5
Why not? How you can do it in maths? Find logic, implement in code.. edit: can you share your idea..? so that we can understand what you expecting.....
31st May 2023, 11:07 AM
Jayakrishna 🇮🇳
+ 4
Cool-Coder and DinoBambino gave the best answer from my pov, just to give further idea Incase you hate numbers You can retrieve the input as a string, then create a custom function that parses it.. this is definitely a longer process but sometimes that's what you need for example in the present code otherwise the maths answers given is the best https://code.sololearn.com/ctT51Glxm3zE/?ref=app
1st Jun 2023, 8:48 AM
Mirielle
Mirielle - avatar
+ 2
There are multiple ways. Easiest is probably: 32 / 10 = 3 32 % 10 = 2
1st Jun 2023, 1:52 AM
DinoBambino
+ 1
You're not doing any math here, so %c seems like the easiest answer. edit: sorry, c brain there; just use char x, y; instead of int x, y;
31st May 2023, 1:15 PM
Orin Cook
Orin Cook - avatar
0
Faran allahverdi It is possible but you will need two inputs :- Eg. Int x,y; cin>>x; cin>>y; Input*: x=3 & y=2 Output*: 3 2
31st May 2023, 2:16 PM
Alhaaj [LESS ACTIVE]
Alhaaj [LESS ACTIVE] - avatar