separate integer less than 1000

separate integer less than 1000 to the value of hundreds, tens and units.

read enter a number <1000, these numbers correspond to separate the components of hundreds of tens and units, to write its output in the form of its components a “hundreds” b “dozens” c “unit”

algoritma :

Deklarasi
bil : integer {input}
a “ratusan” + b “puluhan” + c “satuan” : integer {output}

Deskripsi
Read (bil) (bil<1000)
ratusan<– bil /100 {mendapatkan nilai a ratusan}
puluhan <–( bil – ratusan*100 )/10 {mendapatkan nilai b puluhan}
satuan <–(bil – ratusan*100 – puluhan) {mendapatkan nilai c satuan}

program C++

#include <iostream.h>
#include <conio.h>

class hitung{
private:
int bil;
public:
int ratusan();
int puluhan();
int satuan();

};
void hitung::pemisahan(){
ratusan=bil/100;
puluhan=(bil - ratusan*100)/10;
satuan=bil-ratusan*100-puluhan;

cout<<"MEMISAHKAN BILANGAN INTEGER"<<endl;
cout<<"Masukkan nilai bilangan <1000 : "; cin>>bil;
cout<<ratusan<<" Ratusan + " << puluhan <<" Puluhan + "<< satuan <<" Satuan ";

}

int main(){
hitung x;
x.pemisahan();

getch();
return 0;

}
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: