Program deret dengan if-else pada C++

#include<iostream.h>
#include<conio.h>
main()
{
char pilih;
int i,n,hasil;
cout<<“\n ############################## \n “;
cout<<“\n A. Bilangan Positif \n”;
cout<<“\n B. Bilangan Negatif \n”;
cout<<“\n C. Bilangan Ganjil \n”;
cout<<“\n D. Bilangan Genap \n”;
cout<<“\n ############################## \n”;
cout<<“\n Pilihan Anda ? “;cin>>pilih;
clrscr();
if (pilih==’a’||pilih==’A’)
{
cout<<“Masukkan Banyak Deret ?”;cin>>n;
for (i=1;i<=n;i++)
{
if (i>0)
cout<<” “<<i<<‘\t’;
}
}
else if (pilih==’b’||pilih==’B’)
{
cout<<“Masukkan Banyak Deret ?”;cin>>n;
for (i=1;i<=n;i++)
{
if(-i<0)
cout<<” “<<-i<<‘\t’;
}
}
else if (pilih==’c’||pilih==’C’)
{
cout<<“Masukkan Banyak Deret ?”;cin>>n;
for (i=1;i<=n;i++)
{
if(i%2==0)
cout<<” “<<i<<‘\t’;
}
}
else if (pilih==’d’||pilih==’D’)
{
cout<<“Masukkan Banyak Deret ?”;cin>>n;
for (i=1;i<=n;i++)
{
if(i%2==1)
cout<<” “<<i<<‘\t’;
}
}
else cout<<“Pilihan Anda Salah……”;
}

HASILNYA :

Semoga bermanfaat ^_^

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