Reversing the Value

reverse a number or numbers that you input it, contrast with the recursive, reversing the value of this instance we have a number 2 then outputannya is 2.1.

Algoritma reserve

{Membalik nilai dari sebuah angka}

Deklarasi

n          : integer {input}

Deskripsi

Write n

dibalik=0;

while(n>0)

dibalik=(dibalik*10)+(n%10);

n/=10;

write dibalik

program C++

#include <iostream.h>

#include <conio.h>

class reserve

{

public:

int proses();

void keluaran();

private:

int n,dibalik;

};

int reserve::proses()

{

cout<<"masukan angka yg akan di balik angkanya : ";

cin>>n;

dibalik=0;

while(n>0)

{

dibalik=(dibalik*10)+(n%10);

n/=10;

}

return dibalik;

}

void reserve::keluaran()

{

cout<<endl<<endl<<"angka "<<n<<"setelah dibalik menjadi = "<<dibalik;

}

int main()

{

reserve bilangan;

bilangan.proses();

bilangan.keluaran();

getch();

}
  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: