samedi 25 juillet 2020

Description of Numbers using c ++

Given an N number, you are asked to describe each digit of that number. Description as follows: For example N = 421, the description is 4 hundreds, 2 dozens and 1 unit. For example N = 12345, the description is 1 thousand, 2 thousands, 3 hundreds, 4 tens and 5 units.

Input Format

1 line of number N

Constraints

0 <N <100,000

Output Format

m digits of the number N line, which contains digits and the description of the numbers separated by spaces.

Sample Input 0

123

Sample Output 0

1 hundreds

2 tens

3 units

Explanation 0

Appropriate description of the problem

Sample Input 1

40021

Sample Output 1

4 puluhribuan

0 ribuan

0 ratusan

2 puluhan

1 satuan

this is my code :

#include

#include

using namespace std;

void uang(int x){

 int puluhanribu,ribuan,ratusan,puluhan,satuan;

if(x<=123){
     ratusan=x/100;
     puluhan=(x- ratusan*100)/10;
     satuan=(x- ratusan*100-puluhan*10);
     cout<<ratusan<<" ratusan"<<endl;
     cout<<puluhan<<" puluhan"<<endl;
     cout<<satuan<<" satuan"<<endl;
     }

 else if (x<100000){
     puluhanribu=x/10000;
     ribuan=(x- puluhanribu*10000)/1000;
     ratusan=(x- puluhanribu*10000-ribuan*1000)/100;
     puluhan=(x-puluhanribu*10000-ribuan*1000-ratusan*100)/10;
     satuan=(x-puluhanribu*10000-ribuan*1000-ratusan*100-puluhan*10);
     cout<<puluhanribu<<" puluhribuan"<<endl;
     cout<<ribuan<<" ribuan"<<endl;
     cout<<ratusan<<" ratusan"<<endl;
     cout<<puluhan<<" puluhan"<<endl;
     cout<<satuan<<" satuan"<<endl;
     }

 }

int main(int argc, char *argv[]) {

int input;

cin>>input;

uang(input);

return EXIT_SUCCESS;

}

Aucun commentaire:

Enregistrer un commentaire