ini adalah program mencetak segirtiga dan jajar genjang menggunakan C++
#include<iostream.h>
#include<conio.h>
main(){
char yt;
int pilih,n,i,k,j,pil,h;
awal:
clrscr();
cout<<" MENU UTAMA \n";
cout<<"==========================\n";
cout<<"1. cetak segitiga\n";
cout<<"2. cetak jajar genjang\n";
cout<<"3. EXIT\n";
cout<<"==========================\n";
cout<<"pilih menu : ";
cin>>pilih;
cout<<endl;
clrscr();
switch (pilih)
{
case 1:
{
cout<<"masukan tinggi segitiga : ";cin>>n;
for (i=1;i<=n;i++)
{ for (j=n;j>=i;j--)
{cout<<" ";}
for (k=1;k<=i;k++)
{cout<<" *";}
cout<<endl;
}
}
cout<<"==========================\n";
cout<<"apakah anda ingin mengulang program ini? [y/t] ";cin>>yt;
if(yt=='Y'||yt=='y')
{goto awal;}else
if(yt=='T'||yt=='t')
{goto selesai;}
else;
break;
case 2:
{
cout<<"masukan tinggi jajar genjang : ";cin>>n;
for (int i=1;i<=n;i++)
{
if (i%2==0)
{
for (j=n;j>=i;j--)
{cout<<" ";}
for(int k=n;k>=1;k--)
{
cout<<k;
} }
else
{
for (j=n;j>=i;j--)
{cout<<" ";}
for(int j=1;j<=n;j++)
{
cout<<j;
} }
cout<<endl;
}
}
cout<<"==========================\n";
cout<<"apakah anda ingin mengulang program ini? [y/t] ";cin>>yt;
if(yt=='Y'||yt=='y')
{goto awal;}else
if(yt=='T'||yt=='t')
{goto selesai;}
else;
break;
}selesai:
defaulf:
clrscr();
{cout<<"==sampai jumpa==";}
}
Wednesday, May 20, 2015
Subscribe to:
Post Comments (Atom)
0 komentar:
Post a Comment