Menampilkan bangun persegi biner dan Bangun segitiga biner

program c++

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

using namespace std;

void persegi(){
int baris, temp;
cout << “Input batas : “;
cin >> baris;
temp = baris;
for(int i=1; i<=baris; i++){
for(int j=1; j<=baris; j++){
if(j==i||j==temp)
cout << “0 “;
else
cout << “1 “;
}
temp–;
cout << endl;
}
}

void segitiga(){
int l, k, m = 1;
cout << “Input batas : “;
cin  >> l;
for(int i=1;i<=(l+4);i++){
if(i%2==0) k = 0; else k = 1;
m = k;
for(int j=1;j<=i;j++){
m++;
if(i+j<=(l+5)){
if(m%2==1){
cout << “0 “;
}else{
cout << “1 “;
}
}
}
cout<<endl;
}
}

int main(){
int pilih;
char ulang;
mulai :
cout << “Algoritma Pemrograman”<<endl;
cout << “=========================================”<<endl;
cout << “1. Menampilkan bangun persegi biner”<<endl;
cout << “1. Menampilkan bangun segitiga biner”<<endl;
cout << “—————————————–“<<endl;
cout << “Inputkan pilihan 1-2 : “;
cin >> pilih;
cout << endl;
if(pilih==1) persegi(); else segitiga();
cout << “\nAnda ingin mencoba lagi y/t : “;
fflush(stdin);
cin >> ulang;
cout << endl;
if(ulang==’y’) goto mulai;
getch();
return EXIT_SUCCESS;
}

Iklan

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 )

Foto Google

You are commenting using your Google 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 )

Connecting to %s