Algoritma dan Program Perkalian Himpunan

Algoritma Perkalian Himpunan :

{Menampilkan himpunan A dan himpunan B kemudian menampilkan hasil perkalian himpunan A dan himpunan B}Deklarasi :
A,B : string
banyakA,banyakB : integer
Deskripsi :
banyakA ß input banyak data himpunanAbanyakB ß input banyak data himpunanBfor i to banyakA doA[i] ß input data himpunanA

for j to banyakB do

B[j] ß input data himpunanB

for i to banyakA do

A[i] ß data himpunanA

for j to banyakB do

B[j] ß data himpunanB

for i to banyakA do

for j to banyakB do

A[i] , B[j] ß himpunanA x himpunanB

Implementasi dalam Program C++

#include <iostream>
#include <conio.h>
#include <string.h>
using namespace std;

 int main(){

int banyakA, banyakB;
string A[10],B[10];

cout<<"Masukkan banyaknya himpunan A : ";
cin>>banyakA;
cout<<"Masukkan banyaknya himpunan B : ";
cin>>banyakB;
cout<<endl;

cout<<"Himpunan A = ";
for(int i=0; i<banyakA; i++){
cin>>A[i];
}
cout<<endl;

cout<<"Himpunan B = ";
for(int j=0; j<banyakB; j++){
cin>>B[j];
}
cout<<endl;
cout<<"Himpunan A = {";
for(int i=0; i<banyakA; i++){
cout<<A[i]<<",";
}
cout<<"}";
cout<<endl;
             cout<<"Himpunan B = {";
for(int j=0; j<banyakB; j++){
cout<<B[j]<<",";
}
cout<<"}";
cout<<endl;
cout<<"Himpunan A x B = {";
for(int i=0; i<banyakA; i++){
for(int j=0; j<banyakB; j++){
cout<<"("<<A[i]<<",";
cout<<B[j]<<"),";
}
}
cout<<"}";

getch();
return 0;
}

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