Bil. Ganjil setelah diurutkan

Posted: 1 Juli 2013 in Praktikum Alpro

Source C++ :

#include <cstdlib>
#include <iostream>

using namespace std;
class mengurutkan{
public:
void input();
void urut();
void output();
private:
int temp,n,pos,array[1000];};
void mengurutkan::input(){
cout<<“Masukkan jumlah bilangan : “;cin>>n;
for (int i = 1; i <= n; i++){
cout<<“Masukkan bilangan ke-“<<i<<” : “;cin>>array[i];}
}
void mengurutkan::urut(){
for (int i = 1; i <= n; i++)
{
temp = array[i];
pos = i – 1;

while ((pos >= 0) && (temp < array [pos]))
{
array[pos + 1] = array[pos];
pos–;
}
array[pos + 1] = temp;
}}
void mengurutkan::output(){
cout<<“Setelah diurutkan : \n| “;
for (int i = 1; i <= n; i++){
cout<<array[i]<<” | “;}
cout<<endl<<“\n|”;
for (int i = 1; i <= n; i++){
if (array[i]%2==1)
cout<<“Bilangan ganjil = “<<array[i]<<” | “<<endl;}
}
int main(int argc, char *argv[])
{
mengurutkan x;
x.input();
x.urut();
x.output();

system(“PAUSE”);
return EXIT_SUCCESS;
}

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s