Algoritma Program Gabungan Dua Himpunan, Himpunan A dan Himpunan B. Dengan Syarat Dalam Suatu Himpunan Tidak Boleh Ada Anggota yang Sama.
PROGRAM GABUNGAN
DEKLARASI
var na, nb, i, j, flag : integer;
const NMaks := 100;
A : array [1. .NMaks] of integer;
B : array [1. .NMaks] of integer;
ALGORITMA
/**Baca Himpunan A**/
read (na);
for i:= to na do
read (A[i]);
endfor
/**Baca HImpunan B**/
read (nb);
for j:= to nb do
read (B[j]);
endfor
/**GABUNGAN**/
for i:=1 to na do
write (A[i]);
endfor
for j:=1 to nb do
if A[i] = B[j] then
flag := 1;
endif
endfor
for j:=1 to nb do
flag := 1;
for i:=1 to na do
if A[i}=B[j] then
flag := 0;
endif
endfor
if flag=1 then
write (B[j]);
endif
endfor
Untuk Coding C++ Gabungan Dua Himpunan
#include <iostream>
using namespace std;
int main ()
{
int na, nb,flag, i, j;
int Maks = 100;
int A[Maks], B[Maks];
//*Baca Himpunan A*//
cout <<"Banyak Himpunan A = "; cin >>na;
for (i=1; i<=na; i++)
{
cout << "A["<<i<<"] = "; cin>> A[i];
}
//*Baca Himpunan B*//
cout <<"Banyak Himpunan B = "; cin >>nb;
for (j=1;j<=nb; j++)
{
cout << "B["<<j<<"] = "; cin>> B[j];
}
//*GABUNGAN*//
cout <<"Gabungan = {";
for (i=1; i<=na; i++)
{
cout <<A[i]<<",";
}
for (j=1; j<=nb; j++)
{
flag =1;
for (i=1; i<=na; i++)
{
if (A[i] == B[j])
{
flag=0;
}
}
if (flag == 1)
{
cout <<B[j];
cout <<",";
}
}
cout << "}";
system ('PAUSE');
}
Ini Dia Hasil Execute nya :
Salam Semua
-prmiesti
PROGRAM GABUNGAN
DEKLARASI
var na, nb, i, j, flag : integer;
const NMaks := 100;
A : array [1. .NMaks] of integer;
B : array [1. .NMaks] of integer;
ALGORITMA
/**Baca Himpunan A**/
read (na);
for i:= to na do
read (A[i]);
endfor
/**Baca HImpunan B**/
read (nb);
for j:= to nb do
read (B[j]);
endfor
/**GABUNGAN**/
for i:=1 to na do
write (A[i]);
endfor
for j:=1 to nb do
if A[i] = B[j] then
flag := 1;
endif
endfor
for j:=1 to nb do
flag := 1;
for i:=1 to na do
if A[i}=B[j] then
flag := 0;
endif
endfor
if flag=1 then
write (B[j]);
endif
endfor
Untuk Coding C++ Gabungan Dua Himpunan
#include <iostream>
using namespace std;
int main ()
{
int na, nb,flag, i, j;
int Maks = 100;
int A[Maks], B[Maks];
//*Baca Himpunan A*//
cout <<"Banyak Himpunan A = "; cin >>na;
for (i=1; i<=na; i++)
{
cout << "A["<<i<<"] = "; cin>> A[i];
}
//*Baca Himpunan B*//
cout <<"Banyak Himpunan B = "; cin >>nb;
for (j=1;j<=nb; j++)
{
cout << "B["<<j<<"] = "; cin>> B[j];
}
//*GABUNGAN*//
cout <<"Gabungan = {";
for (i=1; i<=na; i++)
{
cout <<A[i]<<",";
}
for (j=1; j<=nb; j++)
{
flag =1;
for (i=1; i<=na; i++)
{
if (A[i] == B[j])
{
flag=0;
}
}
if (flag == 1)
{
cout <<B[j];
cout <<",";
}
}
cout << "}";
system ('PAUSE');
}
Ini Dia Hasil Execute nya :
Salam Semua
-prmiesti