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?
6 Answers
+ 2
//Method 1
#include <iostream>
using namespace std;
int main() {
int num = 32;
cout << num/10 <<endl;
cout << num%10 << endl;
}
+ 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.....
+ 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
+ 2
There are multiple ways.
Easiest is probably:
32 / 10 = 3
32 % 10 = 2
+ 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;
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