0

Separate some numbers

if there is number 123.456. how to get the output : 100.000 20.000 3.000 400 50 6 or if i input 123. the output is: 100 20 3 just some kind like that. what the fnction should i use? array ? but how ?

5th Jun 2017, 10:40 AM
Sonny Michael
Sonny Michael - avatar
8 odpowiedzi
+ 1
Get the input as a string
5th Jun 2017, 10:47 AM
Andrés04_ve
Andrés04_ve - avatar
+ 1
char number; int size, currenNum; cin >> number; for(int i=0; i < size=sizeof(number); i++){ cout << number[i]; for(int j=0; j<size-i; j++) cout << '0'; cout << endl; }
5th Jun 2017, 10:54 AM
Andrés04_ve
Andrés04_ve - avatar
0
ohh so i can get the size of char as int value?
5th Jun 2017, 11:13 AM
Sonny Michael
Sonny Michael - avatar
0
i cant compile the code, its error. am i missing some library? but i have known the point.
5th Jun 2017, 11:24 AM
Sonny Michael
Sonny Michael - avatar
0
sizeof (number) is yhe size in bytes of the array, a char has 1 byte so every byte is a new char
5th Jun 2017, 12:50 PM
Andrés04_ve
Andrés04_ve - avatar
0
but i got the error: you have to declare char* number as a pointer (array) sorry man
5th Jun 2017, 12:51 PM
Andrés04_ve
Andrés04_ve - avatar
0
tell me the error you get compiling
5th Jun 2017, 12:52 PM
Andrés04_ve
Andrés04_ve - avatar
0
thx man ! awesome
5th Jun 2017, 12:53 PM
Sonny Michael
Sonny Michael - avatar