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 odpowiedzi
+ 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 🇮🇳
+ 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
Alhaaz
Alhaaz - avatar