Program himpunan (kelas 3J)

Program himpunan bagi kelas 3J

  1. Silahkan menuliskan program himpunan menggunakan bahasa apapun baik Java, C, C++, Pascal, Basic, dan sebagainya di bagian komentar.
  2. Jangan lupa menuliskan nama dan NIM anda.
  3. Ingat perhatikan baik-baik kelas anda, selain program / koding tuliskan hasilnya dari alur program yang anda tulis.

61 Responses

  1. #include
    #include
    #define MAX 50

    void main() {
    int i, j, Stat;
    int p, q, n, m;
    int A[MAX];
    int B[MAX];
    int AnB[MAX], AuB[MAX];
    printf(” Nama : Khoirul Ufesy \n”);
    printf(” Kelas: S1-TI-3J \n”);
    printf(” NIM : 09.11.3245 \n”);

    n = 0;
    printf(“\n Masukan panjang Himpunan A = “);
    scanf(“%d”, &n);
    for(i = 0; i < n; i++) {
    printf(" Isi Nilai : ");
    scanf(" %d", &A[i]);
    }
    printf("A = {%i", A[0]);
    for(i = 1; i < n; i++) {
    printf(",%d", A[i]);
    }
    printf("}\n");

    m = 0;
    printf(" Masukan panjang Himpunan B = ");
    scanf("%d", &m);
    for(i = 0; i < m; i++) {
    printf(" Isi Nilai : ");
    scanf("%d", &B[i]);
    }
    printf("B = {%i", B[0]);
    for(i = 1; i < m; i++) {
    printf(",%d", B[i]);
    }
    printf("}\n");

    p = 0;
    for(i = 0; i < n; i++) {
    for(j = 0; j < m; j++) {
    if(A[i] == B[j]) {
    AnB[p] = B[j];
    p = p + 1;
    }
    }
    }
    printf("—————————– \n");
    printf("Maka A irisan B adalah…\n");
    printf("AnB = {%d", AnB[0]);
    for(i = 1; i < p; i++) {
    printf(",%d", AnB[i]);
    }
    printf("}\n");

    Stat = 0;
    q = n;
    for(i = 0; i < n; i++) {
    AuB[i] = A[i];
    }
    for(j = 0; j < m; j++) {
    Stat = 0;
    for(i = 0; i < n; i++) {
    if(B[j] == A[i]) {
    Stat = 1;
    }
    }

    if(Stat == 0) {
    AuB[q] = B[j];
    q = q + 1;
    }
    }
    printf("—————————– \n");
    printf("Maka A gabung B adalah…\n");
    printf("AuB = {%d", AuB[0]);
    for(i = 1; i < q; i++) {
    printf(",%d", AuB[i]);
    }
    printf("}\n");

    getch();
    }

  2. #include
    #include
    #include

    #define ValueMax 25

    typedef float matriks[ValueMax][ValueMax];

    void main()
    {

    intcolA,colB,rowA,rowB,i,j;
    matriks A,B,C;
    int answer;

    do
    {
    clrscr();
    cout<<"\aAndaMemilih Menu PerkalianMatriks\n\n\n";
    cout<<"MATRIKS A : "<<endl<<endl;
    cout<>rowA;
    cout<>colA;
    cout<<endl<<endl;
    cout<<"MATRIKS B : "<<endl<<endl;
    cout<>rowB;
    cout<>colB;
    }
    while (colA!=rowB);

    clrscr();
    cout<<"MasukkanNilaiMatriks A : "<<endl;
    for(i=1;i<=rowA;i++)
    {
    for(j=1;j<=colA;j++)
    {
    cout<<"A["<<i<<","<<j<>A[i][j];
    }
    }

    cout<<endl<<endl;
    cout<<"MasukkanNilaiMatriks B : "<<endl;
    for(i=1;i<=rowB;i++)
    {
    for(j=1;j<=colB;j++)
    {
    cout<<"B["<<i<<","<<j<>B[i][j];
    }
    }

    clrscr();
    cout<<endl;
    //Proses PerkalianMatriks
    if(colA == 1)
    {
    for(i=1;i<=rowA;i++)
    {
    for(j=1;j<=colB;j++)
    {
    C[i][j] = (A[i][1] * B[1][j]);
    }
    }
    }

    if(colA == 2)
    {
    for(i=1;i<=rowA;i++)
    {
    for(j=1;j<=colB;j++)
    {
    C[i][j] = (A[i][1] * B[1][j] + A[i][2] * B[2][j]);
    }
    }
    }

    if(colA == 3)
    {
    for(i=1;i<=rowA;i++)
    {
    for(j=1;j<=colB;j++)
    {
    C[i][j] = (A[i][1] * B[1][j] + A[i][2] * B[2][j] + A[i][3] * B[3][j]);
    }
    }
    }

    if(colA == 4)
    {
    for(i=1;i<=rowA;i++)
    {
    for(j=1;j<=colB;j++)
    {
    C[i][j] = (A[i][1]*B[1][j] + A[i][2]*B[2][j] + A[i][3]*B[3][j] + A[i][4]*B[4][j]);
    }
    }
    }

    if(colA == 5)
    {
    for(i=1;i<=rowA;i++)
    {
    for(j=1;j<=colB;j++)
    {
    C[i][j] = (A[i][1]*B[1][j] + A[i][2]*B[2][j] + A[i][3]*B[3][j] + A[i][4]*B[4][j] + A[i][5]*B[5][j]);
    }
    }
    }

    clrscr();
    //Output Matriks A
    gotoxy(1,5);
    cout<<"A = ";
    for(i=1;i<=rowA;i++)
    {
    for(j=1;j<=colA;j++)
    {
    gotoxy(2+4*j,2+2*i);
    cout<<A[i][j];
    }
    }

    //Output Matriks B
    gotoxy(1,17);
    cout<<"B = ";
    for(i=1;i<=rowB;i++)
    {
    for(j=1;j<=colB;j++)
    {
    gotoxy(2+4*j,14+2*i);
    cout<<B[i][j];
    }
    }

    //Output Matriks C
    gotoxy(1,30);
    cout<<"C = ";
    for(i=1;i<=rowA;i++)
    {
    for(j=1;j<=colA;j++)
    {
    gotoxy(3+4*j,27+2*i);
    cout<<A[i][j];
    }
    }

    gotoxy(25,30);
    cout<<" X ";
    for(i=1;i<=rowB;i++)
    {
    for(j=1;j<=colB;j++)
    {
    gotoxy(26+4*j,27+2*i);
    cout<<B[i][j];
    }
    }

    gotoxy(43,30);
    cout<<" = ";
    for(i=1;i<=rowA;i++)
    {
    for(j=1;j<=colB;j++)
    {
    gotoxy(45+4*j,27+2*i);
    cout<<C[i][j];
    }
    }

    getch();
    }

    Aminatun
    09.11.3273

  3. import java.io.*;
    class relasi
    {private static BufferedReader radzi = new BufferedReader (new InputStreamReader (System.in));
    public static void main(String[] args) throws Exception{
    System.out.print(“masukan banyaknya himpunan A :”);
    String s = radzi.readLine();
    int x = Integer.parseInt(s);
    int himpA [] = new int [x];
    for(int i = 0;i
    {System.out.print(“masukan element himpunan A ke – ” +(i+1)+” :”);
    String a = radzi.readLine();
    himpA [i] = Integer.parseInt(a);
    }
    System.out.print(“A = {“);
    for (int i=0;i
    {
    System.out.print(himpA[i]);
    if(i != x-1)
    System.out.print(“,”);
    }
    System.out.println(“}”);
    System.out.println();
    System.out.println(” jenis relasi”);
    System.out.println(“=================”);
    System.out.println(“1. Reflektif Sederhana”);
    System.out.println(“2. Simetris Sederhana”);
    System.out.println(“3. Transitif Sederhana”);
    System.out.println(“======================”);
    System.out.print(“Masukan pilihan anda : “);
    String r = radzi.readLine();
    int d = Integer.parseInt(r);
    switch (d)
    {
    case 1:
    System.out.print(“relasi R = { “);
    for (int i= 0;i
    {
    for (int j =0;j
    {
    if (himpA [i]== himpA[j])
    {
    System.out.print(“(” +himpA [i]+ “,” +himpA [j]+ “)”);
    if (j != x-1)
    System.out.print(“,”);
    }
    }
    }
    System.out.println(“}”);
    break;

    case 2:
    System.out.print(“relasi R = { “);
    for (int i= 0;i
    {
    for (int j =0;j
    {
    if (himpA [i]!= himpA[j])
    {
    System.out.print(“(” +himpA [i]+ “,” +himpA [j]+ “)”);
    if (j != x-1)
    System.out.print(“,”);
    }}}
    System.out.println(“}”);
    break;

    case 3 :
    System.out.print(“relasi R = { “);
    for (int i= 0;i
    {
    for (int j =0;j
    {
    if (himpA [i]!= himpA[j])
    {
    if(i%2!=0)
    {
    if(j%2==0)
    {
    System.out.print(“(” +himpA [i]+ “,” +himpA [j]+ “)”);
    if (j != x-1)
    System.out.print(“,”);
    }
    else
    {
    if(j%2 != 0)
    {
    System.out.print(“(” +himpA [i]+ “,” +himpA [j]+ “)”);
    if (j != x-1)
    System.out.print(“,”);
    }
    }
    }
    }
    }
    }
    System.out.println(“}”);
    break;
    default :
    System.out.print(“pilihan tidak ada dalam aftar”);
    break;
    }
    }
    }

    Nama : Trisna Yogatama
    Kelas : S1 TI 3j
    Nomer : 09.11.3280

  4. #include
    #include

    void main() {
    int i, j;
    int k, n, m;
    int A[25];
    int B[25];
    int AnB[25], AuB[25];

    n = 0;
    printf(“Masukan panjang Himpunan A : “);
    scanf(“%d”, &n);
    for(i = 0; i < n; i++) {
    printf("Isi Nilai : ");
    scanf("%d", &A[i]);
    }
    printf("A = {%i", A[0]);
    for(i = 1; i < n; i++) {
    printf(",%d", A[i]);
    }
    printf("}\n");

    m = 0;
    printf("Masukan panjang Himpunan B : ");
    scanf("%d", &m);
    for(i = 0; i < m; i++) {
    printf("Isi Nilai : ");
    scanf("%d", &B[i]);
    }
    printf("B = {%i", B[0]);
    for(i = 1; i < m; i++) {
    printf(",%d", B[i]);
    }
    printf("}\n");

    // Proses Irisan Himpunan
    k = 0;
    for(i = 0; i < n; i++) {
    for(j = 0; j < m; j++) {
    if(A[i] == B[j]) {
    AnB[k] = B[j];
    k = k + 1;
    }
    }
    }
    printf("Maka A irisan B adalah…\n");
    printf("AnB = {%i", AnB[0]);
    for(i = 1; i < n; i++) {
    printf(",%i", AnB[i]);
    }
    printf("}\n");

    // Proses Gabung Himpunan
    for(i = 0; i < n; i++) {
    AuB[i] = A[i];
    }
    for(i = 0; i < n; i++) {
    for(j = 0; j < m; j++) {
    if(A[i] != B[j]) {
    AuB[n + i] = A[i];
    n = n + i;
    }
    }
    }
    printf("Maka A gabung B adalah…\n");
    printf("AuB = {%i", AuB[0]);
    for(i = 1; i < n; i++) {
    printf(",%i", AuB[i]);
    }
    printf("}\n");

    getch();
    }

  5. Code
    ====
    /*
    * PROGRAM HIMPUNAN
    *
    * NAMA : MIFTAKHURROKHMAT
    * NIM : 09.11.3229
    * KELAS : S1TI-3I
    *
    * STMIK AMIKOM YOGYAKARTA
    */
    #include // load library i/o
    #include // load library STL (Standard Template Library)
    #include // load library iterator
    #include

    using namespace std;

    int main() {
    const int MAX = 100; // definisikan maksimal anggota himpunan = 100
    int nA, nB, nU; // deklarasikan variabel nA = n|A|, nB = n|B|, nU = n|U|
    int himpunanA[MAX]; // deklarasikan array himpunanA
    int himpunanB[MAX]; // deklarasikan array himpunanB
    int himpunanU[MAX]; // deklarasikan array himpunanU = Universal

    // intro
    cout << "\n PROGRAM HIMPUNAN\n\n Nama\t: Miftakhurrokhmat\n NIM\t: 09.11.3207\n Kelas\t: S1TI-3I\n\n STMIK AMIKOM YOGYAKARTA\n";
    cout << "—————————————–\n";
    // masukkan jumlah anggota
    cout <> nU;
    cout <> nA;
    // cek apakah n|A| > n|U|
    // jika benar maka terjadi error, dan pengguna diminta untuk memasukkan ulang nilai n|A|
    if(nA > nU){
    cout <> nA;
    }
    cout <> nB;
    // cek apakah n|B| > n|U|
    // jika benar maka terjadi error, dan pengguna diminta untuk memasukkan ulang nilai n|B|
    if(nB > nU){
    cout <> nB;
    }

    cout << "\n HIMPUNAN UNIVERSAL : \n";
    // masukkan nilai dari masing-masing elemen himpunan Universal
    for (int i=0; i<nU; i++){
    cout << " Masukkan anggota Himpunan Universal ke-" << i+1 <> himpunanU[i];
    }

    cout << "\n HIMPUNAN A : \n";

    // masukkan nilai dari masing-masing elemen himpunan A
    for (int i=0; i<nA; i++){
    cout << " Masukkan anggota Himpunan A ke-" << i+1 <> himpunanA[i];
    }

    cout << "\n HIMPUNAN B : \n";
    // masukkan nilai dari masing-masing elemen himpunan B
    for (int i=0; i<nB; i++){
    cout << " Masukkan anggota Himpunan B ke-" << i+1 <> himpunanB[i];
    }
    cout << "\n—————————————–\n DATA YANG DIMASUKKAN";
    cout << "\n—————————————–\n";

    cout << "\n HIMPUNAN U \t: ";
    for(int i=0; i<nU; i++)
    cout << himpunanU[i] << " ";
    cout << "\n HIMPUNAN A \t: ";
    for(int i=0; i<nA; i++)
    cout << himpunanA[i] << " ";
    cout << "\n HIMPUNAN B \t: ";
    for(int i=0; i<nB; i++)
    cout << himpunanB[i] << " ";

    cout << "\n\n—————————————–\n OUTPUT";
    cout << "\n—————————————–\n\n";

    // panggil fungsi set_intersection dari library algorithm (STL)
    // fungsi ini akan menghasilkan irisan (intersection) dari himpunan A dan himpunan B
    // hasil intersection berupa iterator
    cout << " A INTERSECTION B \t: ";
    set_intersection(himpunanA, himpunanA+nA, himpunanB, himpunanB+nB, ostream_iterator(cout, ” “));

    // panggil fungsi set_difference dari library algorithm (STL)
    // fungsi ini akan menghasilkan difference dari himpunan A dan himpunan B
    // hasil difference berupa iterator
    cout << "\n\n A DIFFERENCE B \t: ";
    set_difference(himpunanA, himpunanA+nA, himpunanB, himpunanB+nB, ostream_iterator(cout, ” “));

    cout << "\n\n B DIFFERENCE A \t: ";
    set_difference(himpunanB, himpunanB+nB, himpunanA, himpunanA+nA, ostream_iterator(cout, ” “));

    // panggil fungsi set_union dari library algorithm (STL)
    // fungsi ini akan menghasilkan gabungan (union) dari himpunan A dan himpunan B
    // hasil union berupa iterator
    cout << "\n\n A UNION B \t\t: ";
    set_union(himpunanA, himpunanA+nA, himpunanB, himpunanB+nB, ostream_iterator(cout, ” “));

    // karena Complement A = U difference A, maka untuk mencari Complement A dapat menggunakan fungsi set_difference
    cout << "\n\n COMPLEMENT A \t\t: ";
    set_difference(himpunanU, himpunanU+nU, himpunanA, himpunanA+nA, ostream_iterator(cout, ” “));

    // karena Complement B = U difference B, maka untuk mencari Complement B dapat menggunakan fungsi set_difference
    cout << "\n\n COMPLEMENT B \t\t: ";
    set_difference(himpunanU, himpunanU+nU, himpunanB, himpunanB+nB, ostream_iterator(cout, ” “));

    cout << "\n\n—————————————–\n\n";
    getch();

    return 0;

    }

    HASIL
    =====

    PROGRAM HIMPUNAN

    Nama : Miftakhurrokhmat
    NIM : 09.11.3207
    Kelas : S1TI-3I

    STMIK AMIKOM YOGYAKARTA
    —————————————–
    Masukkan jumlah Himpunan Universal : 5
    Masukkan jumlah Himpunan A : 2
    Masukkan jumlah Himpunan B : 3

    HIMPUNAN UNIVERSAL :
    Masukkan anggota Himpunan Universal ke-1 : 1
    Masukkan anggota Himpunan Universal ke-2 : 2
    Masukkan anggota Himpunan Universal ke-3 : 3
    Masukkan anggota Himpunan Universal ke-4 : 4
    Masukkan anggota Himpunan Universal ke-5 : 5

    HIMPUNAN A :
    Masukkan anggota Himpunan A ke-1 : 2
    Masukkan anggota Himpunan A ke-2 : 3

    HIMPUNAN B :
    Masukkan anggota Himpunan B ke-1 : 1
    Masukkan anggota Himpunan B ke-2 : 2
    Masukkan anggota Himpunan B ke-3 : 4

    —————————————–
    DATA YANG DIMASUKKAN
    —————————————–

    HIMPUNAN U : 1 2 3 4 5
    HIMPUNAN A : 2 3
    HIMPUNAN B : 1 2 4

    —————————————–
    OUTPUT
    —————————————–

    A INTERSECTION B : 2

    A DIFFERENCE B : 3

    B DIFFERENCE A : 1 4

    A UNION B : 1 2 3 4

    COMPLEMENT A : 1 4 5

    COMPLEMENT B : 3 5

    —————————————–

  6. //nama : eko mardianto
    //kelas : s1 TI 1j
    //nim : 09.11.3311

    #include
    #include
    void main (){
    int a[100], b[100];
    int c[100], u[100];
    int i,j,n,m,e;
    bool z;
    cout<>n;

    for (i=0; i<n; i++){
    cout<<"data "<<(i+1)<>a[i];
    }
    cout<<" A = { ";
    for (i=0; i<n; i++){
    cout<<a[i]<<" ";
    }
    cout<<"}";
    cout<>m;
    for (j=0; j<m; j++){
    cout<<"data "<<(j+1)<>b[j];
    }
    cout<<" B = { ";
    for (j=0; j<m; j++){
    cout<<b[j]<<" ";
    }
    cout<<"}";
    cout<<endl<<endl;

    cout<<"\n\nA n B = { ";
    for (i=0; i<n; i++){
    for (j=0; j<m; j++){
    if (a[i]==b[j]){
    e=e+1;
    c[e]=a[i];
    cout<<c[e]<<" " ;
    }
    }
    }
    cout<<"}"<<endl<<endl;
    cout<<endl<<endl;

    cout<<"A U B = { ";
    for (i=0; i<n; i++){
    u[i]=a[i];
    cout<<u[i]<<" ";
    }
    for (i=0; i<m; i++){
    z=false;
    for (j=0;j<n;j++){
    if (b[i]== a[j]){
    z=true;
    }

    }
    if (!z){
    u[i+n]=b[i];
    cout<<u[i+n]<<" ";
    }
    }
    cout<<"}"<<endl<<endl;
    getch();
    }

    hasilnya:

    masukkan banyak himpunan A : (input misal 2)
    data 1: (misal 1)
    data 2: (misal 3)
    A ={1 3}
    masukkan banyak himpunan B : (input misal 3)
    data 1: (misal 2)
    data 2: (misal 3)
    data 3: (misal 4)
    B = {2 3 4}

    A ={ 3 }

    A ={1 2 3 4}

  7. //nama : eko mardianto
    //kelas : s1 TI 1j
    //nim : 09.11.3311

    #include
    #include
    void main (){
    int a[100], b[100];
    int c[100], u[100];
    int i,j,n,m,e;
    bool z;
    cout<>n;

    for (i=0; i<n; i++){
    cout<<"data "<<(i+1)<>a[i];
    }
    cout<<" A = { ";
    for (i=0; i<n; i++){
    cout<<a[i]<<" ";
    }
    cout<<"}";
    cout<>m;
    for (j=0; j<m; j++){
    cout<<"data "<<(j+1)<>b[j];
    }
    cout<<" B = { ";
    for (j=0; j<m; j++){
    cout<<b[j]<<" ";
    }
    cout<<"}";
    cout<<endl<<endl;

    cout<<"\n\nA n B = { ";
    for (i=0; i<n; i++){
    for (j=0; j<m; j++){
    if (a[i]==b[j]){
    e=e+1;
    c[e]=a[i];
    cout<<c[e]<<" " ;
    }
    }
    }
    cout<<"}"<<endl<<endl;
    cout<<endl<<endl;

    cout<<"A U B = { ";
    for (i=0; i<n; i++){
    u[i]=a[i];
    cout<<u[i]<<" ";
    }
    for (i=0; i<m; i++){
    z=false;
    for (j=0;j<n;j++){
    if (b[i]== a[j]){
    z=true;
    }

    }
    if (!z){
    u[i+n]=b[i];
    cout<<u[i+n]<<" ";
    }
    }
    cout<<"}"<<endl<<endl;
    getch();
    }

  8. nama: galuh ajeng puspita
    nim:09.11.3239

    //program himpunan
    #include
    #include
    #include
    #include
    int him1[100];
    int him2[100];
    char ulang;
    int i,j,jum1,jum2,t,pilih,l;
    int union1[100],irisan[100];
    bool sama;
    void main(){
    cout<<"\t\tMenu \n";
    cout<<"1. mencari union dari himpunan\n";
    cout<<"0. keluar\n";
    cout<"———————————–";
    cout<<endl;
    ulang='y';
    do
    {

    cout<<endl;
    cout<>pilih;
    switch (pilih)
    {
    case 1:
    cout<<"Program mencari union dari himpunan"<<endl;
    cout<<"masukkan data himpunan pertama!"<<endl;
    cout<>jum1;
    for (i=1;i<=jum1;i++){
    cout<<"data "<<i<>him1[i];
    }
    cout<<"himpunan pertama:";
    for (i=1;i<=jum1;i++){
    cout<<him1[i]<<" ";
    }
    cout<<endl;
    cout<<"masukkan data himpunan kedua!"<<endl;
    cout<>jum2;
    for (j=1;j<=jum2;j++){
    cout<<"data "<<j<>him2[j];
    }
    cout<<"himpunan kedua:";
    for (j=1;j<=jum2;j++){
    cout<<him2[j]<<" ";
    }
    cout<<endl;
    //perintah union
    cout<<"Union dari himpunan satu dan himpunan dua adalah:"<<endl;
    for (i=1;i<=jum1;i++){
    union1[i]=him1[i];
    cout<<union1[i]<<", ";
    }
    for (i=1;i<=jum2;i++){
    sama=false;
    for (j=1;j<=jum1;j++){
    if (him2[i]== him1[j]){
    sama=true;
    }

    }
    if (!sama){
    union1[i+jum1]=him2[i];
    cout<<union1[i+jum1]<<", ";
    }
    }
    break;
    case 0:ulang=='t';
    default:cout<<"bukan pilahan yang valid!";
    cout<<endl;
    cout<>ulang;
    }
    }while (ulang==’y’);
    }

    hasil:
    1.mencari union dari himpunan
    0.keluar

    masukkan pilihan anda
    ex: 1
    program mencari union dari himpunan
    masukkan data himpunan pertama
    banyak data:
    data 1, dst
    masukkan data himpunan kedua
    banyak data:
    data 1, dst
    Union dari himpunan satu dan himpunan dua adalah

  9. nama: galuh ajeng puspita
    nim:09.11.3239

    //program himpunan
    #include
    #include
    #include
    #include
    int him1[100];
    int him2[100];
    char ulang;
    int i,j,jum1,jum2,t,pilih,l;
    int union1[100],irisan[100];
    bool sama;
    void main(){
    cout<<"\t\tMenu \n";
    cout<<"1. mencari union dari himpunan\n";
    cout<<"0. keluar\n";
    cout<"———————————–";
    cout<<endl;
    ulang='y';
    do
    {

    cout<<endl;
    cout<>pilih;
    switch (pilih)
    {
    case 1:
    cout<<"Program mencari union dari himpunan"<<endl;
    cout<<"masukkan data himpunan pertama!"<<endl;
    cout<>jum1;
    for (i=1;i<=jum1;i++){
    cout<<"data "<<i<>him1[i];
    }
    cout<<"himpunan pertama:";
    for (i=1;i<=jum1;i++){
    cout<<him1[i]<<" ";
    }
    cout<<endl;
    cout<<"masukkan data himpunan kedua!"<<endl;
    cout<>jum2;
    for (j=1;j<=jum2;j++){
    cout<<"data "<<j<>him2[j];
    }
    cout<<"himpunan kedua:";
    for (j=1;j<=jum2;j++){
    cout<<him2[j]<<" ";
    }
    cout<<endl;
    //perintah union
    cout<<"Union dari himpunan satu dan himpunan dua adalah:"<<endl;
    for (i=1;i<=jum1;i++){
    union1[i]=him1[i];
    cout<<union1[i]<<", ";
    }
    for (i=1;i<=jum2;i++){
    sama=false;
    for (j=1;j<=jum1;j++){
    if (him2[i]== him1[j]){
    sama=true;
    }

    }
    if (!sama){
    union1[i+jum1]=him2[i];
    cout<<union1[i+jum1]<<", ";
    }
    }
    break;
    case 0:ulang=='t';
    default:cout<<"bukan pilahan yang valid!";
    cout<<endl;
    cout<>ulang;
    }
    }while (ulang==’y’);
    }

    hasil:
    1.mencari union dari himpunan
    0.keluar

    masukkan pilihan anda
    ex: 1
    program mencari union dari himpunan
    masukkan data himpunan pertama
    banyak data:
    data 1, dst
    masukkan data himpunan kedua
    banyak data:
    data 1, dst
    Union dari himpunan satu dan himpunan dua adalah

  10. nama : ade yahya ns
    nim : 09.11.3292
    kelas : S1TI3J

    #include
    #include
    #include
    #include

    void prog();
    int main()
    {
    prog();
    return 0;
    }

    void prog()
    {
    int jmlx, jmly, i, a[10], b[10];
    char choice[2];
    printf(“N.I.M : 09.11.3292\n”);
    printf(“Nama : Ade Yahya NurSinggih\n”);
    printf(“KELAS : S1TI3J\n”);
    printf(“==============================\n”);
    printf(“==============================\n”);
    printf(“Input Jumlah Unsur Himpunan X (Maksimal 10): “);
    scanf(“%d”,&jmlx);
    for (i=1;i<=jmlx;i++)
    {
    printf("Input Unsur ke-%d = ", i);
    scanf("%d", &a[i]);
    }
    printf("==============================\n");
    printf("Input Jumlah Unsur Himpunan Y (Maksimal 10): ");
    scanf("%d",&jmly);

    for (i=1;i<=jmly;i++)
    {
    printf("Input Unsur ke-%d = ", i);
    scanf("%d", &b[i]);
    }

    printf("==============================\n");
    printf("==============================\n");

    printf("X Irisan Y = ");
    for(i=1;i<=jmly;i++)
    {
    if (a[1]==b[i])
    printf(" %d,",a[1]);
    else
    cout<<"";

    if (a[2]==b[i])
    printf(" %d,",a[2]);
    else
    cout<<"";

    if (a[3]==b[i])
    printf(" %d,",a[3]);
    else
    cout<<"";

    if (a[4]==b[i])
    printf(" %d,",a[4]);
    else
    cout<<"";

    if (a[5]==b[i])
    printf(" %d,",a[5]);
    else
    cout<<"";

    if (a[6]==b[i])
    printf(" %d,",a[6]);
    else
    cout<<"";

    if (a[7]==b[i])
    printf(" %d,",a[7]);
    else
    cout<<"";

    if (a[8]==b[i])
    printf(" %d,",a[8]);
    else
    cout<<"";

    if (a[9]==b[i])
    printf(" %d,",a[9]);
    else
    cout<<"";

    if (a[10]==b[i])
    printf(" %d,",a[10]);
    else
    cout<<"";
    }
    printf("\nX Gabungan Y = ");
    for(i=1;i<jmlx;i++)
    {
    printf(" %d,", a[i]);
    }
    for(i=1;i<jmly;i++)
    {
    if (b[i]!= a[i])
    printf(" %d,", b[i]);
    else
    printf("");
    }
    printf("\n==============================\n");
    printf("==============================\n");

    cout<<endl<<"Mau coba lagi ga? (1 = ya, 2 = tidak)?: \n";
    cin.getline(choice,3);
    if(choice[0] == '1')
    prog();
    else
    exit(0);
    getch();
    }

  11. // nama : pujo hari saputro
    //NIM : 09.11.3264
    //KLS : S1 TI 3J

    #include
    #include
    #include
    #include
    int him1[100];
    int him2[100];
    int i,j,jum1,jum2,l;
    int irisan[100];
    bool sama;
    void main(){
    cout<<"masukkan data himpunan pertama!"<<endl;
    cout<>jum1;
    for (i=1;i<=jum1;i++){
    cout<<"data "<<i<>him1[i];
    }
    cout<<"himpunan pertama:";
    for (i=1;i<=jum1;i++){
    cout<<him1[i]<<" ";
    }
    cout<<endl;
    cout<<"masukkan data himpunan kedua!"<<endl;
    cout<>jum2;
    for (j=1;j<=jum2;j++){
    cout<<"data "<<j<>him2[j];
    }
    cout<<"himpunan kedua:";
    for (j=1;j<=jum2;j++){
    cout<<him2[j]<<" ";
    }
    cout<<endl;
    //perintah irisan
    cout<<"Irisan dari kedua himpunan tersebut adalah:";
    l=0;
    for (i=1;i<=jum1;i++)
    {
    for (j=1;j<=jum2;j++)
    {
    if (him1[i]==him2[j])
    {
    l=l+1;
    irisan[l]=him1[i];
    cout<<irisan[l]<<" ";
    }
    }
    }
    getch();
    }

  12. Nama : Tri Supriaadi
    NIM : 09.11.3265
    Kelas : S1 TI 3J

    #include
    #include
    #include
    #include

    void menu(), Union(), irisan(),salah();

    void Union() {
    clrscr();
    int h1[100];
    int h2[100];
    int i,j,j1,j2,l;
    int union1[100];
    bool sama;
    cout<<" MENCARI UNION HIMPUNAN A DAN B"<<endl<<endl;
    cout<<" Data Himpunan A"<<endl;
    cout<>j1;
    for (i=1;i<=j1;i++){
    cout<<" Elemen ke "<<i<>h1[i];
    }
    cout<<" Himpunan A : { ";
    for (i=1;i<=j1;i++){
    cout<<h1[i]<<" ";
    }
    cout<<"}"<<endl<<endl<<endl;
    cout<<" Data Himpunan B"<<endl;
    cout<>j2;
    for (j=1;j<=j2;j++){
    cout<<" Elemen ke "<<j<>h2[j];
    }
    cout<<" Himpunan B = { ";
    for (j=1;j<=j2;j++){
    cout<<h2[j]<<" ";
    }
    cout<<"}";
    cout<<endl<<endl;
    cout<<" Union Dari Himpunan A Dan B Adalah:"<<endl;
    cout<<" A Union B : { ";
    for (i=1;i<=j1;i++){
    union1[i]=h1[i];
    cout<<union1[i]<<" ";
    }
    for (i=1;i<=j2;i++){
    sama=false;
    for (j=1;j<=j1;j++){
    if (h2[i]== h1[j]){
    sama=true;
    }

    }
    if (!sama){
    union1[i+j1]=h2[i];
    cout<<union1[i+j1]<<" ";
    }
    }
    cout<<"}"<<endl<<endl;
    salah();
    getch();
    }

    void irisan() {
    clrscr();
    int h1[100];
    int h2[100];
    int i,j,j1,j2,l;
    int irisan[100];
    bool sama;
    cout<<" MENCARI IRISAN HIMPUNAN A DAN B"<<endl<<endl;
    cout<<" Data Himpunan A"<<endl;
    cout<>j1;
    for (i=1;i<=j1;i++){
    cout<<" Elemen ke "<<i<>h1[i];
    }
    cout<<" Himpunan A : { ";
    for (i=1;i<=j1;i++){
    cout<<h1[i]<<" ";
    }
    cout<<"}";
    cout<<endl<<endl;
    cout<<" Data Himpunan B"<<endl;
    cout<>j2;
    for (j=1;j<=j2;j++){
    cout<<" Elemen ke "<<j<>h2[j];
    }
    cout<<" Himpunan B : {";
    for (j=1;j<=j2;j++){
    cout<<h2[j]<<" ";
    }
    cout<<"}";
    cout<<endl<<endl;
    cout<<" Irisan Dari Himpunan A Dan B Adalah :"<<endl;
    cout<<" A Irisan B : { ";
    l=0;
    for (i=1;i<=j1;i++){
    for (j=1;j<=j2;j++){
    if (h1[i]==h2[j]){
    l=l+1;
    irisan[l]=h1[i];
    cout<<irisan[l]<<" ";
    }
    }
    }
    cout<<"}"<<endl<<endl;
    salah();
    getch();
    }

    void salah(){
    char c;
    cout<>c;
    switch(c){
    case ‘Y’:
    case ‘y’:
    menu();
    break;
    case ‘N’:
    case ‘n’:
    exit(1);
    }
    getch();
    }

    void menu()
    {
    clrscr();
    int pilih;
    cout<<" NAMA : TRI SUPRIADI"<<endl;
    cout<<" NIM : 09.11.3265"<<endl;
    cout<<" KELAS : S1 TI 3J"<<endl;
    cout<<" ==================="<<endl<<endl;
    cout<<" PROGRAM HIMPUNAN"<<endl;
    cout<<" ****************"<<endl;
    cout<<" 1. Union "<<endl;
    cout<<" 2. Irisan "<<endl;
    cout<>pilih;
    if(pilih==1){
    Union();
    }
    else if(pilih==2){
    irisan();
    }
    else {
    salah();
    }
    getch();
    }

    int main(){
    menu();
    getch();
    }

  13. //09.11.3258
    // krisna ardy p

    #include
    #include
    #include
    #include

    void prog();
    int main()
    {
    prog();
    return 0;
    }

    void prog()
    {
    int jmlx, jmly, i, a[10], b[10];
    char choice[2];

    printf(“Input Jumlah Unsur Himpunan X (Maksimal 10): “);
    scanf(“%d”,&jmlx);

    for (i=1;i<=jmlx;i++)
    {
    printf("Input Unsur ke-%d = ", i);
    scanf("%d", &a[i]);
    }
    printf("—————————————————-\n");
    printf("Input Jumlah Unsur Himpunan Y (Maksimal 10): ");
    scanf("%d",&jmly);

    for (i=1;i<=jmly;i++)
    {
    printf("Input Unsur ke-%d = ", i);
    scanf("%d", &b[i]);
    }

    printf("—————————————————-\n");
    printf("—————————————————-\n");

    printf("X Irisan Y = ");
    for(i=1;i<=jmly;i++)
    {
    if (a[1]==b[i])
    printf(" %d,",a[1]);
    else
    cout<<"";

    if (a[2]==b[i])
    printf(" %d,",a[2]);
    else
    cout<<"";

    if (a[3]==b[i])
    printf(" %d,",a[3]);
    else
    cout<<"";

    if (a[4]==b[i])
    printf(" %d,",a[4]);
    else
    cout<<"";

    if (a[5]==b[i])
    printf(" %d,",a[5]);
    else
    cout<<"";

    if (a[6]==b[i])
    printf(" %d,",a[6]);
    else
    cout<<"";

    if (a[7]==b[i])
    printf(" %d,",a[7]);
    else
    cout<<"";

    if (a[8]==b[i])
    printf(" %d,",a[8]);
    else
    cout<<"";

    if (a[9]==b[i])
    printf(" %d,",a[9]);
    else
    cout<<"";

    if (a[10]==b[i])
    printf(" %d,",a[10]);
    else
    cout<<"";
    }
    printf("\nX Gabungan Y = ");
    for(i=1;i<jmlx;i++)
    {
    printf(" %d,", a[i]);
    }
    for(i=1;i<jmly;i++)
    {
    if (b[i]!= a[i])
    printf(" %d,", b[i]);
    else
    printf("");
    }
    printf("\n—————————————————-\n");
    printf("—————————————————-\n");

    cout<<endl<<"Mau coba lagi ga? (1 = ya, 2 = tidak)?: \n";
    cin.getline(choice,3);
    if(choice[0] == '1')
    prog();
    else
    exit(0);
    getch(); }

  14. Nama=Wahyu Iskandar
    Kelas=S1TI3J
    NIM=09.11.3308

    package DiskretHimpunan;

    public class Main {
    public static void main(String[] args) {

    //Deklarasi variabel
    int[] X, Y, Irisan, Gabungan, BedaSetangkup, SelisihAB, SelisihBA;
    int i, j, k, l, m, n, p, q, r, tmp;

    //Instantiasi objek
    X= new int [50];
    Y= new int [50];
    Irisan= new int [50];
    Gabungan= new int [50];
    BedaSetangkup= new int [50];
    SelisihAB= new int [50];
    SelisihBA= new int [50];

    System.out.println(“”);
    System.out.println(“Aplikasi Operasi Himpunan Dari Himpunan A dan B”);
    System.out.println(“———————————————————-“);

    //Input Himpunan A
    m = 0;
    System.out.print(“Jumlah elemen Himpunan A : “);
    m = Integer.parseInt(System.console().readLine());
    for(i = 0; i < m; i++) {
    System.out.print("Input elemen A : ");
    X[i]=Integer.parseInt(System.console().readLine());
    }

    //Menampilkan Himpunan A
    System.out.print("A = {"+X[0]);
    for(i = 1; i < m; i++) {
    System.out.print("," + X[i]);
    }
    System.out.print("}\n");
    System.out.println("");

    //Input Himpunan B
    n = 0;
    System.out.print("Jumlah elemen Himpunan B : ");
    n = Integer.parseInt(System.console().readLine());
    for(i = 0; i < n; i++) {
    System.out.print("Input elemen B : ");
    Y[i]=Integer.parseInt(System.console().readLine());
    }

    //Menampilkan Himpunan B
    System.out.print("B = {" + Y[0]);
    for(i = 1; i < n; i++) {
    System.out.print("," + Y[i]);
    }
    System.out.print("}\n");
    System.out.println("");

    //Proses Pencarian Irisan
    k = 0;
    for(i = 0; i < m; i++) {
    for(j = 0; j < n; j++) {
    if(X[i] == Y[j]) {
    Irisan[k] = Y[j];
    k = k + 1;
    }
    }
    }
    //Menampilkan Irisan Himpunan
    System.out.println("———————————————————-");
    System.out.print("Jadi A irisan B adalah\n");
    System.out.print("AnB = {"+ Irisan[0]);
    for(i = 1; i < k; i++) {
    System.out.print(","+ Irisan[i]);
    }
    System.out.print("}\n");
    System.out.println("");

    //Proses Penggabungan Himpunan
    tmp = 0;
    l = m;
    for(i = 0; i < m; i++) {
    Gabungan[i] = X[i];
    }

    for(j = 0; j < n; j++) {
    tmp = 0;
    for(i = 0; i < m; i++) {
    if(Y[j] == X[i]) {
    tmp = 1;
    }
    }

    if(tmp == 0) {
    Gabungan[l] = Y[j];
    l = l + 1;
    }
    }
    //Menampilkan Gabungan Himpunan
    System.out.print("Jadi A gabung B adalah\n");
    System.out.print("AuB = {"+ Gabungan[0]);
    for(i = 1; i < l; i++) {
    System.out.print(","+Gabungan[i]);
    }
    System.out.print("}\n");
    System.out.println("");

    //Proses Selisih A-B
    q = 0;
    for (i = 0; i < m; i++){
    tmp = 0;
    for(j = 0; j < n; j++) {
    if( X[i] == Y[j]) {
    tmp = 1;
    }
    }

    if(tmp == 0) {
    SelisihAB[q] = X[i];
    q = q + 1;
    }
    }
    //Menampilkan Selisih Himpunan A-B
    System.out.print("Jadi Selisih A – B adalah\n");
    System.out.print("(A-B) = {"+ SelisihAB[0]);
    for(i = 1; i < q; i++) {
    System.out.print(","+SelisihAB[i]);
    }
    System.out.print("}\n");
    System.out.println("");

    //Proses Selisih B-A
    r=0;
    for(j = 0; j < n; j++) {
    tmp = 0;
    for(i = 0; i < m; i++) {
    if(Y[j] == X[i]) {
    tmp = 1;
    }
    }

    if(tmp == 0) {
    SelisihBA[r] = Y[j];
    r = r + 1;
    }
    }
    //Menampilkan Selisih Himpunan A-B
    System.out.print("Jadi Selisih B – A adalah\n");
    System.out.print("(B-A) = {"+ SelisihBA[0]);
    for(i = 1; i < r; i++) {
    System.out.print(","+SelisihBA[i]);
    }
    System.out.print("}\n");
    System.out.println("");

    //Proses Pencarian Beda Setangkup/Symmetric Different
    p = 0;
    for (i = 0; i < m; i++){
    tmp = 0;
    for(j = 0; j < n; j++) {
    if( X[i] == Y[j]) {
    tmp = 1;
    }
    }

    if(tmp == 0) {
    BedaSetangkup[p] = X[i];
    p = p + 1;
    }
    }

    for(j = 0; j < n; j++) {
    tmp = 0;
    for(i = 0; i < m; i++) {
    if(Y[j] == X[i]) {
    tmp = 1;
    }
    }

    if(tmp == 0) {
    BedaSetangkup[p] = Y[j];
    p = p + 1;
    }
    }
    //Menampilkan Beda Setangkup Himpunan
    System.out.print("Jadi Beda Setangkup A dan B adalah\n");
    System.out.print("(A-B)u(B-A) = {"+ BedaSetangkup[0]);
    for(i = 1; i < p; i++) {
    System.out.print(","+BedaSetangkup[i]);
    }
    System.out.print("}\n");
    System.out.println("———————————————————-");
    }
    }

  15. //DWI RS SEPTIAN
    //09.11.3260
    //S1TI3J
    //program himpunan
    import javax.swing.*;
    class himpunan
    {
    public static void main(String[] args)
    {
    int na=0 , nb=0;
    na = Integer.parseInt(JOptionPane.showInputDialog(“masukan banyak elemen A : “));
    int a[] = new int [na];
    nb = Integer.parseInt(JOptionPane.showInputDialog(“masukan banyak elemen B : “));
    int b[] = new int [nb];

    for(int i=0;i
    a[i]=Integer.parseInt(JOptionPane.showInputDialog(“nilai A ke”+(i+1)));
    }
    for (int j=0;j
    {
    b[j]=Integer.parseInt(JOptionPane.showInputDialog(“nilai B ke”+(j+1)));
    }
    System.out.print(“himpunan A={ “);
    for(int x=0;x
    System.out.print(a[x]+” “);
    }
    System.out.println(“}”);
    System.out.print(“himpunan B={ “);
    for(int x=0;x
    System.out.print(b[x]+” “);
    }
    System.out.println(“}”);
    System.out.print(“nilai A Irisan B = {“);
    for(int i=0;i
    for(int j=0;j<=nb-1;j++){
    if(a[i]==b[j]){
    System.out.print(a[i]+" ");
    }
    }
    }
    System.out.println("}");
    }
    }

  16. // Nama : Gulam Hazmin, NIM : 09.11.3285

    Program Himpunan;

    Uses wincrt;

    Type Sets = Set Of Char;
    Var A, B, Irisan, Union, Selisih1, Selisih2 : sets; lagi : char;
    Procedure Input (var N:sets; y:byte);
    var i : byte;
    ch : char;

    begin
    for i:= 1 to 5 do

    begin
    gotoxy(22+i*3,y);
    ch:=upcase(readkey);
    N:=N+[ch];
    if i=5 then

    begin
    gotoxy(22+i*3,y);writeln(ch,’}’);

    end

    else
    begin
    gotoxy(22+i*3,y);Write(ch,’, ‘);

    end;

    end;

    end

    Procedure InputData;

    var i: byte;
    begin
    gotoxy(10,2); write(‘==========================’);
    gotoxy(10,3); write(‘ OPERASI HIMPUNAN ‘);
    gotoxy(10,4); write(‘==========================’);
    gotoxy(10,5); write(‘Himpunan A : {‘);Input(A,5);
    gotoxy(10,6); write(‘Himpunan B : {‘);Input(B,6);
    end;

    Procedure Cetak (N:sets; y:byte);

    var i: char;
    begin
    gotoxy(30,y);
    for i:= #00 to #255 do
    if N * [i] = [i] then write(‘ ‘,i,’ ‘);
    write(‘ }’);
    end;

    Procedure Tampilkan;

    Begin
    gotoxy(10,15);write(‘Irisan (A,B) = { ‘);
    gotoxy(10,17);write(‘Gabungan (A,B) = { ‘);
    gotoxy(10,19);write(‘Selisih (A,B) = { ‘);
    gotoxy(10,21);write(‘Selisih (B,A) = { ‘);
    Cetak(Irisan,15); Cetak(Union,17);
    Cetak(Selisih1,19);Cetak(Selisih2,21);
    end;

    Procedure Proses;

    Begin
    Union := A + B;
    Irisan := A * B;
    Selisih1 := (A-B);
    Selisih2 := (B-A);
    Tampilkan;

    repeat
    gotoxy(20,23);write(‘ Coba Lagi [Y/T] :’);
    lagi:=UpCase(readkey);
    Until lagi in [‘Y’,’T’];
    donewincrt;
    end;

    Begin
    While lagi ‘T’ do

    Begin
    clrscr;
    InputData;
    Proses;
    end;

    End.

    // Program akan meminta masukkan nilai sebanyak 6 nilai untuk himpunan A dan juga 6 Nilai untuk himpunan B. Kemudian, melalui syntax code yang telah ditulis seperti diatas, akan langsung dimunculkan selisih A-B, Selisih B-A, Irisan dan Gabungan kedua himpunan tersebut.

    Hasilnya bisa dilihat disini, Pak.

    Terima Kasih.

  17. #include
    #include
    #define MAX 50

    void main() {
    int i, j, Stat;
    int p, q, n, m;
    int A[MAX];
    int B[MAX];
    int AnB[MAX], AuB[MAX];
    printf(” Nama : Kunto Adhy Dewahyu \n”);
    printf(” Kelas: S1-TI-3J \n”);
    printf(” NIM : 09.11.3276 \n”);

    n = 0;
    printf(“\n Masukan panjang Himpunan A = “);
    scanf(“%d”, &n);
    for(i = 0; i < n; i++) {
    printf(" Isi Nilai : ");
    scanf(" %d", &A[i]);
    }
    printf("A = {%i", A[0]);
    for(i = 1; i < n; i++) {
    printf(",%d", A[i]);
    }
    printf("}\n");

    m = 0;
    printf(" Masukan panjang Himpunan B = ");
    scanf("%d", &m);
    for(i = 0; i < m; i++) {
    printf(" Isi Nilai : ");
    scanf("%d", &B[i]);
    }
    printf("B = {%i", B[0]);
    for(i = 1; i < m; i++) {
    printf(",%d", B[i]);
    }
    printf("}\n");

    p = 0;
    for(i = 0; i < n; i++) {
    for(j = 0; j < m; j++) {
    if(A[i] == B[j]) {
    AnB[p] = B[j];
    p = p + 1;
    }
    }
    }
    printf("—————————– \n");
    printf("Maka A irisan B adalah…\n");
    printf("AnB = {%d", AnB[0]);
    for(i = 1; i < p; i++) {
    printf(",%d", AnB[i]);
    }
    printf("}\n");

    Stat = 0;
    q = n;
    for(i = 0; i < n; i++) {
    AuB[i] = A[i];
    }
    for(j = 0; j < m; j++) {
    Stat = 0;
    for(i = 0; i < n; i++) {
    if(B[j] == A[i]) {
    Stat = 1;
    }
    }

    if(Stat == 0) {
    AuB[q] = B[j];
    q = q + 1;
    }
    }
    printf("—————————– \n");
    printf("Maka A gabung B adalah…\n");
    printf("AuB = {%d", AuB[0]);
    for(i = 1; i < q; i++) {
    printf(",%d", AuB[i]);
    }
    printf("}\n");

    getch();
    }

  18. #include
    #include

    int HimpunanPertama[50];
    int HimpunanKedua[50];
    int i,j,jumlahSatu,jumlahDua,l;
    int Irisan[50], UnionSatu[50];
    bool Same;

    void main(){
    cout<<" ================================================== \n \n "<<endl;
    cout<<" 1.) Masukkan Data Himpunan Pertama \n"<<endl;
    cout<>jumlahSatu;
    for (i=1;i<=jumlahSatu;i++){
    cout<<"Data "<<i<>HimpunanPertama[i];
    }
    cout<<"himpunan pertama adalah ";
    cout<<"{";
    for(i=1;i<=jumlahSatu;i++){
    cout<<HimpunanPertama[i]<<", ";
    }
    cout<<"}\n";

    cout<<"\n 2.) Masukkan data himpunan kedua \n"<<endl;
    cout<>jumlahDua;
    for (j=1;j<=jumlahDua;j++){
    cout<<"Data "<<j<>HimpunanKedua[j];
    }
    cout<<"himpunan kedua adalah ";
    cout<<"{";
    for (j=1;j<=jumlahDua;j++){
    cout<<HimpunanKedua[j]<<", ";
    }cout<<"}\n \n ";

    cout<<" ================================================== \n \n "<<endl;
    cout<<" Hasil dari Kedua Himpunan tersebut adalah : \n \n "<<endl;
    cout<<"\n A.) Irisan dari kedua himpunan tersebut adalah ";
    cout<<"{";
    l=0;
    for (i=1;i<=jumlahSatu;i++){
    for (j=1;j<=jumlahDua;j++){
    if (HimpunanPertama[i]==HimpunanKedua[j]){
    l=l+1;
    Irisan[l]=HimpunanKedua[j];
    cout<<Irisan[l]<<", ";
    }
    }
    } cout<<"}";

    cout<<"\n\n B.) Gabungan dari kedua himpunan tersebut adalah ";
    // perintah gabungan
    cout<<"{";
    for (i=1;i<=jumlahSatu;i++){
    UnionSatu[i]=HimpunanPertama[i];
    cout<<UnionSatu[i]<<", ";
    }
    for (i=1;i<=jumlahDua;i++){
    Same=false;
    for (j=1;j<=jumlahSatu;j++){
    if (HimpunanKedua[i]== HimpunanPertama[j]){
    Same=true;
    }
    }
    if (!Same){
    UnionSatu[i+jumlahSatu]=HimpunanKedua[i];
    cout<<UnionSatu[i+jumlahSatu]<<", ";
    }
    } cout<<"} ";

    getch(); }

  19. //Program irisan dan gabungan himpunan
    //Nama: Lia Farokhah
    //Nim :09.11.3279 / S1_TI_3J
    #include
    #include

    int himpunan1[15];
    int himpunan2[15];
    int i,j,jum1,jum2,l;
    int irisan[10], gabungan[10];
    bool sama;

    void main(){
    cout<<"Nama: LIA FAROKHAH"<<endl;
    cout<<"Nim:09.11.3279/ S1_TI_3J"<<endl;
    cout<<" =====Silahkan masukkan data anda!!====="<<endl;
    cout<>jum1;
    for (i=1;i<=jum1;i++){
    cout<<"data "<<i<>himpunan1[i];
    }
    cout<<"Anggota bilangan X:";
    for(i=1;i<=jum1;i++){
    cout<<himpunan1[i]<<" ";
    }
    cout<<endl;

    cout<>jum2;
    for (j=1;j<=jum2;j++){
    cout<<"data "<<j<>himpunan2[j];
    }
    cout<<"Anggota bilangan Y:";
    for (j=1;j<=jum2;j++){
    cout<<himpunan2[j]<<" ";
    } cout<<endl;

    //Mencari irisan ^_^
    cout<<"\n Irisan dari himpunan x,y tersebut adalah: ";
    l=0;
    for (i=1;i<=jum1;i++){
    for (j=1;j<=jum2;j++){
    if (himpunan1[i]==himpunan2[j]){
    l=l+1;
    irisan[l]=himpunan2[j];
    cout<<irisan[l]<<" ";
    }
    }
    }

    cout<<"\n\n Gabungan himpunan x,y adalah: ";
    // gabungan
    for (i=1;i<=jum1;i++){
    gabungan[i]=himpunan1[i];
    cout<<gabungan[i]<<", ";
    }
    for (i=1;i<=jum2;i++){
    sama=false;
    for (j=1;j<=jum1;j++){
    if (himpunan2[i]== himpunan1[j]){
    sama=true;
    }
    }
    if (!sama){
    gabungan[i+jum1]=himpunan2[i];
    cout<<gabungan[i+jum1]<<", "<<endl;
    cout<<"=======program is finish==========";
    }
    }

    getch();
    }

  20. #include

    #include

    #include

    #include

    using namespace std;

    int main() {
    const int MAX = 100; // definisikan maksimal anggota himpunan = 100
    int hA,hB,hU; // deklarasikan variabel nA = n|A|, nB = n|B|, nU = n|U|
    int himpunanA[MAX]; // deklarasikan array himpunanA
    int himpunanB[MAX]; // deklarasikan array himpunanB
    int himpunanU[MAX]; // deklarasikan array himpunanU = Universal

    printf(“\n TUGAS MATEMATIKA DISKRIT PROGRAM MENGHITUNG HIMPUNANA\n\n \t\tSTMIK AMIKOM YOGYAKARTA\n\n\n”);

    printf(“——————————————————-\n”);

    printf(“\t Nama\t : Angga Prasetya\n\n NIM\t : 09.11.3251\n\n Kelas\t : S1TI-3J\n\n”);

    printf(“——————————————————-\n”);

    printf(“Tekan Enter Untuk Memulai Penghitungan……………..”);

    getch();

    clrscr();

    printf(“\n________________________________________________”);

    printf(“\n\t PROGRAM MENGHITUNG HIMPUNAN “);

    printf(“\n\================================================”);

    printf(“\n\n Masukkan jumlah Himpunan Universal : “);
    scanf(“%d”,&hU);
    printf(” Masukkan jumlah Himpunan A : “);
    scanf(“%d”,&hA);
    if(hA > hU){
    printf(” jumlah anggota A tidak boleh lebih dari jumlah Anggota Universal\n Masukkan lagi jumlah Himpunan A : “);
    scanf(“%d”,&hA);
    }
    printf(” Masukkan jumlah Himpunan B : “);
    scanf(“%d”,&hB);

    if(hB > hU){
    printf(” jumlah anggota B tidak boleh lebih dari jumlah Anggota Universal\n Masukkan lagi jumlah Himpunan B : “);
    scanf(“%d”,&hB);
    }

    printf(“\n HIMPUNAN UNIVERSAL : \n”);
    for (int i=0; i<hU; i++){
    printf(" Masukkan anggota Himpunan Universal ke-%d : ", i+1);
    scanf("%d",&himpunanU[i]);
    }

    printf("\n HIMPUNAN A : \n");

    for (int i=0; i<hA; i++){
    printf(" Masukkan anggota Himpunan A ke-%d : ", i+1);
    scanf("%d",&himpunanA[i]);
    }

    printf("\n HIMPUNAN B : \n");

    for (int i=0; i<hB; i++){
    printf(" Masukkan anggota Himpunan B ke-%d : ", i+1);
    scanf("%d",&himpunanB[i]);
    }

    printf("\n—————————————–\n DATA YANG DIMASUKKAN");
    printf("\n—————————————–\n");

    printf("\n HIMPUNAN U \t: ");
    for(int i=0; i<hU; i++)
    printf("himpunanU[i]");
    printf("\n HIMPUNAN A \t: ");
    for(int i=0; i<hA; i++)
    printf("himpunanA[i]");
    printf("\n HIMPUNAN B \t: ");
    for(int i=0; i<hB; i++)
    printf("himpunanB[i]");

    clrscr();
    printf("\n—————————————————–\n \t HASIL PENGHITUNGAN-NYA");
    printf("\n—————————————————–\n\n");

    printf("\t A INTERSECTION B \t: ");
    set_intersection(himpunanA, himpunanA+hA, himpunanB, himpunanB+hB, ostream_iterator(cout, ” “));

    printf(“\n\n\t A UNION B \t\t: “);
    set_union(himpunanA, himpunanA+hA, himpunanB, himpunanB+hB, ostream_iterator(cout, ” “));

    printf(“\n\n\t A DIFFERENCE B \t: “);
    set_difference(himpunanA, himpunanA+hA, himpunanB, himpunanB+hB, ostream_iterator(cout, ” “));

    printf(“\n\n\t B DIFFERENCE A \t: “);
    set_difference(himpunanB, himpunanB+hB, himpunanA, himpunanA+hA, ostream_iterator(cout, ” “));

    printf(“\n\n\t COMPLEMENT A \t\t: “);
    set_difference(himpunanU, himpunanU+hU, himpunanA, himpunanA+hA, ostream_iterator(cout, ” “));

    printf(“\n\n\t COMPLEMENT B \t\t: “);
    set_difference(himpunanU, himpunanU+hU, himpunanB, himpunanB+hB, ostream_iterator(cout, ” “));

    printf(“\n\n—————————————————\n\n”);

    getch();

    }

  21. //Nama : Prantyo
    //NIM : 09.11.3266
    //Kelas : S1 TI 3J

    #include
    #include
    #define MAX 50

    void main() {
    int i, j, Stat;
    int p, q, n, m;
    int A[MAX];
    int B[MAX];
    int AnB[MAX], AuB[MAX];

    n = 0;
    printf(“–Program Himpunan Matematika Diskret–\n”);
    printf(“Isi banyaknya nilai Himpunan A = “);
    scanf(“%d”, &n);
    for(i = 0; i < n; i++) {
    printf("Isi nilai himpunan: ");
    scanf("%d", &A[i]);
    }
    printf("A = {%i", A[0]);
    for(i = 1; i < n; i++) {
    printf(",%d", A[i]);
    }
    printf("}\n");

    m = 0;
    printf("Isi banyaknya nilai Himpunan B = ");
    scanf("%d", &m);
    for(i = 0; i < m; i++) {
    printf("Isi nilai himpunan= ");
    scanf("%d", &B[i]);
    }
    printf("B = {%i", B[0]);
    for(i = 1; i < m; i++) {
    printf(",%d", B[i]);
    }
    printf("}\n");

    p = 0;
    for(i = 0; i < n; i++) {
    for(j = 0; j < m; j++) {
    if(A[i] == B[j]) {
    AnB[p] = B[j];
    p = p + 1;
    }
    }
    }
    printf("Hasil A n B =\n");
    printf("A n B = {%d", AnB[0]);
    for(i = 1; i < p; i++) {
    printf(",%d", AnB[i]);
    }
    printf("}\n");

    Stat = 0;
    q = n;
    for(i = 0; i < n; i++) {
    AuB[i] = A[i];
    }
    for(j = 0; j < m; j++) {
    Stat = 0;
    for(i = 0; i < n; i++) {
    if(B[j] == A[i]) {
    Stat = 1;
    }
    }

    if(Stat == 0) {
    AuB[q] = B[j];
    q = q + 1;
    }
    }

    printf("Hasil A U B =\n");
    printf("A U B = {%d", AuB[0]);
    for(i = 1; i < q; i++) {
    printf(",%d", AuB[i]);
    }
    printf("}\n");

    getch();
    }

    //Contoh Hasil Alur Program:

    //–Program Himpunan Matematika Diskret–
    //Isi banyaknya nilai Himpunan A = 4
    //Isi nilai himpunan:1
    //Isi nilai himpunan:2
    //Isi nilai himpunan:3
    //Isi nilai himpunan:4
    //A = {1,2,3,4}
    //Isi banyaknya nilai Himpunan B = 5
    //Isi nilai himpunan:2
    //Isi nilai himpunan:3
    //Isi nilai himpunan:4
    //Isi nilai himpunan:5
    //Isi nilai himpunan:6
    //B = {2,3,4,5,6}
    //Hasil A n B =
    //A n B = {2,3,4,5,6}
    //Hasil A U B =
    //A U B = {1,2,3,4,5,6}

  22. /* nama: cahyo asih wibowo
    nim: 09.11.3248
    Kelas:s1ti-3j */

    package tester;

    import java.io.*;

    class Test
    {
    public static void main(String[] args)
    {
    BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
    char [] tmp=null;
    int c,d;

    String str=””;
    while (true)
    {
    try{
    str=br.readLine();
    }catch(IOException e){}
    if(str.equals(“{}”))
    System.out.println(“{{}}”);

    else {
    tmp=str.toCharArray();
    System.out.print(“{{}”);
    for (c=0;c=’0′ && tmp[c]<='z')
    System.out.print(",{"+tmp[c]+"}");
    }

    for (c=0;c<tmp.length ; c++)
    {

    for (d=0;d=’0′ && tmp[c]=’0′ && tmp[d]<='z' && tmp[c]<tmp[d] )
    System.out.print(",{"+tmp[c]+","+tmp[d]+"}");

    }
    }
    }
    str="";
    System.out.print(",{");
    for (c=0;c=’0′ && tmp[c]<='z'){
    if(str.equals(""))
    str =""+tmp[c];
    else
    str +=","+tmp[c];
    }
    }
    System.out.println(str+"}}");
    }

    }

    }
    }

    /* run:
    1,2,3
    {{},{1},{2},{3},{1,2},{1,3},{2,3},{1,2,3}}
    */

  23. Retno dwi wulandari_3286_S1TI3J

    #include
    #include
    #include
    #include
    int him1[100];
    int him2[100];
    char ulang;
    int i,j,jum1,jum2,t,pilih,l;
    int union1[100],irisan[100];
    bool sama;
    void main(){
    cout<<"\t\tMenu \n";
    cout<<"1. mencari union dari himpunan\n";
    cout<<"0. keluar\n";
    cout<"———————————–";
    cout<<endl;
    ulang='y';
    do
    {

    cout<<endl;
    cout<>pilih;
    switch (pilih)
    {
    case 1:
    cout<<"Program mencari union dari himpunan"<<endl;
    cout<<"masukkan data himpunan pertama!"<<endl;
    cout<>jum1;
    for (i=1;i<=jum1;i++){
    cout<<"data "<<i<>him1[i];
    }
    cout<<"himpunan pertama:";
    for (i=1;i<=jum1;i++){
    cout<<him1[i]<<" ";
    }
    cout<<endl;
    cout<<"masukkan data himpunan kedua!"<<endl;
    cout<>jum2;
    for (j=1;j<=jum2;j++){
    cout<<"data "<<j<>him2[j];
    }
    cout<<"himpunan kedua:";
    for (j=1;j<=jum2;j++){
    cout<<him2[j]<<" ";
    }
    cout<<endl;
    //perintah union
    cout<<"Union dari himpunan satu dan himpunan dua adalah:"<<endl;
    for (i=1;i<=jum1;i++){
    union1[i]=him1[i];
    cout<<union1[i]<<", ";
    }
    for (i=1;i<=jum2;i++){
    sama=false;
    for (j=1;j<=jum1;j++){
    if (him2[i]== him1[j]){
    sama=true;
    }

    }
    if (!sama){
    union1[i+jum1]=him2[i];
    cout<<union1[i+jum1]<<", ";
    }
    }
    break;
    case 0:ulang=='t';
    default:cout<<"bukan pilahan yang valid!";
    cout<<endl;
    cout<>ulang;
    }
    }while (ulang==’y’);
    }

  24. #include
    #include
    #define MAX 60

    void main() {
    int i, j, Stat;
    int p, q, n, m;
    int F[MAX];
    int A[MAX];
    int FnA[MAX], FuA[MAX];

    printf(“*…………………..Selamat datang……………………..*\n”);
    printf(“\n”);

    printf(“………PROGRAM MENGHITUNG HIMPUNAN IRISAN DAN GABUNGAN………\n”);

    printf(“\n”);
    printf(“\n”);

    n = 0;
    printf(“ketikan panjang nilai himpunan F = “);
    scanf(“%d”, &n);
    for(i = 0; i < n; i++) {
    printf("Angka = ");
    scanf("%d", &F[i]);
    }
    printf("F = {%i", F[0]);
    for(i = 1; i < n; i++) {
    printf(",%d", F[i]);
    }
    printf("}\n");
    printf("\n");

    m = 0;
    printf("ketikan panjang nilai himpunan A = ");
    scanf("%d", &m);
    for(i = 0; i < m; i++) {
    printf("Angka = ");
    scanf("%d", &A[i]);
    }
    printf("A = {%i", A[0]);
    for(i = 1; i < m; i++) {
    printf(",%d", A[i]);
    }
    printf("}\n");
    printf("\n");

    p = 0;
    for(i = 0; i < n; i++) {
    for(j = 0; j < m; j++) {
    if(F[i] == A[j]) {
    FnA[p] = A[j];
    p = p + 1;
    }
    }
    }
    printf("Jadi himpunan F n A \n");
    printf("F n A = {%d", FnA[0]);
    for(i = 1; i < p; i++) {
    printf(",%d", FnA[i]);
    }
    printf("}\n");
    printf("\n");

    Stat = 0;
    q = n;
    for(i = 0; i < n; i++) {
    FuA[i] = F[i];
    }
    for(j = 0; j < m; j++) {
    Stat = 0;
    for(i = 0; i < n; i++) {
    if(A[j] == F[i]) {
    Stat = 1;
    }
    }

    if(Stat == 0) {
    FuA[q] = A[j];
    q = q + 1;
    }
    }

    printf("Jadi himpunan F u A \n");
    printf("F u A = {%d", FuA[0]);
    for(i = 1; i < q; i++) {
    printf(",%d", FuA[i]);
    }
    printf("}\n");
    printf("\n");
    printf("…………..Program finis…………..");

    getch();
    }

    //Faisal Lukman N
    //09.11.3282
    //s1 ti 3j

    //*…………………..Selamat datang……………………..*

    //………PROGRAM MENGHITUNG HIMPUNAN IRISAN DAN GABUNGAN……..

    //ketikan panjang nilai himpunan F = 3
    //Angka = 2
    //Angka = 1
    //Angka = 3
    //F = {2,1,2}

    //ketikan panjang nilai himpunan A = 3
    //Angka = 2
    //Angka = 4
    //Angka = 5
    //A = {2,4,4}

    //Jadi himpunan F n A
    //F n A = {2}

    //Jadi himpunan F u A
    //F u A = {2,1,3,4,5}
    //…………..Program finis…………..

  25. //Alek Bagus Panuntun
    // 09.11.3247
    //S1 TI 3J

    #include
    #include
    #define MAX 50

    void main() {
    int i, j, Stat;
    int p, q, n, m;
    int C[MAX];
    int M[MAX];
    int CnM[MAX], CuM[MAX];

    n = 0;
    printf(“Masukan panjang Himpunan C : “);
    scanf(“%d”, &n);
    for(i = 0; i < n; i++) {
    printf("Isi Nilai : ");
    scanf("%d", &C[i]);
    }
    printf("C = {%i", C[0]);
    for(i = 1; i < n; i++) {
    printf(",%d", C[i]);
    }
    printf("}\n");

    m = 0;
    printf("Masukan panjang Himpunan M : ");
    scanf("%d", &m);
    for(i = 0; i < m; i++) {
    printf("Isi Nilai : ");
    scanf("%d", &M[i]);
    }
    printf("M = {%i", M[0]);
    for(i = 1; i < m; i++) {
    printf(",%d", M[i]);
    }
    printf("}\n");

    p = 0;
    for(i = 0; i < n; i++) {
    for(j = 0; j < m; j++) {
    if(C[i] == M[j]) {
    CnM[p] = M[j];
    p = p + 1;
    }
    }
    }
    printf("Maka C irisan M adalah…\n");
    printf("CnM = {%d", CnM[0]);
    for(i = 1; i < p; i++) {
    printf(",%d", CnM[i]);
    }
    printf("}\n");

    Stat = 0;
    q = n;
    for(i = 0; i < n; i++) {
    CuM[i] = C[i];
    }
    for(j = 0; j < m; j++) {
    Stat = 0;
    for(i = 0; i < n; i++) {
    if(M[j] == C[i]) {
    Stat = 1;
    }
    }

    if(Stat == 0) {
    CuM[q] = M[j];
    q = q + 1;
    }
    }

    printf("Maka C gabung M adalah…\n");
    printf("CuM = {%d", CuM[0]);
    for(i = 1; i < q; i++) {
    printf(",%d", CuM[i]);
    }
    printf("}\n");

    getch();
    }
    //Masukan panjang Himpunan C : 2
    //Isi Nilai : 11
    //Isi Nilai : 22
    // C = {11,22}
    // Masukan panjang Himpunan M : 3
    // Isi nilai : 3
    // Isi Nilai : 2
    // Isi Nilai : 1
    // M = {3,2,1}
    // Maka C irisan M adalah. . .
    // CnM = {1244368}
    // Maka C gabung M adalah. . .
    // CuM = {11.,22,3,2,1}

  26. include stdio.h
    include conio.h

    pak tanda kebaca coding html
    hasil isian saya juga gx kebaca disini pak , ,

    gimana ni pak??

  27. //Alfian
    //09.11.3256
    //SITI-3J

    #include
    #include
    #define MAX 50

    void main() {
    int i, j, Stat;
    int p, q, n, m;
    int K[MAX];
    int L[MAX];
    int KnL[MAX], KuL[MAX];

    n = 0;
    printf(“–===PROGRAM HIMPUNAN MATEMATIKA DISKRET===–\n”);
    printf(“\n”);
    printf(“ALFIAN\n”);
    printf(“09.11.3256\n”);
    printf(“S1TI-3J”);
    getch();
    clrscr();
    printf(“Jumlah Anggota Himpunan K : “);
    scanf(“%d”, &n);
    for(i = 0; i < n; i++) {
    printf("Masukkan Nilai Anggota K : ");
    scanf("%d", &K[i]);
    }
    printf("K = {%i", K[0]);
    for(i = 1; i < n; i++) {
    printf(",%d", K[i]);
    }
    printf("}\n");
    getch();
    clrscr();

    m = 0;
    printf("Jumlah Anggota Himpunan L : ");
    scanf("%d", &m);
    for(i = 0; i < m; i++) {
    printf("Masukkan Nilai Anggota L : ");
    scanf("%d", &L[i]);
    }
    printf("L = {%i", L[0]);
    for(i = 1; i < m; i++) {
    printf(",%d", L[i]);
    }
    printf("}\n");
    getch();
    clrscr();

    p = 0;
    for(i = 0; i < n; i++) {
    for(j = 0; j < m; j++) {
    if(K[i] == L[j]) {
    KnL[p] = L[j];
    p = p + 1;
    }
    }
    }
    printf("K irisan L adalah…\n");
    printf("KnL = {%d", KnL[0]);
    for(i = 1; i < p; i++) {
    printf(",%d", KnL[i]);
    }
    printf("}\n");
    getch();
    clrscr();

    Stat = 0;
    q = n;
    for(i = 0; i < n; i++) {
    KuL[i] = K[i];
    }
    for(j = 0; j < m; j++) {
    Stat = 0;
    for(i = 0; i < n; i++) {
    if(L[j] == K[i]) {
    Stat = 1;
    }
    }

    if(Stat == 0) {
    KuL[q] = L[j];
    q = q + 1;
    }
    }

    printf("K gabungan L adalah…\n");
    printf("KuL = {%d", KuL[0]);
    for(i = 1; i < q; i++) {
    printf(",%d", KuL[i]);
    }
    printf("}\n");
    getch();
    clrscr();
    printf("–===THANK YOU FOR USING THIS PROGRAM===–\n");
    printf("————=======FIN=======————-\n");
    getch();
    }

    //Hasilnya
    //–===PROGRAM HIMPUNAN MATEMATIKA DISKRET===–
    //ALFIAN
    //09.11.3256
    //S1TI-3J
    //
    //Jumlah Anggota Himpunan K : 4
    //Masukkan Nilai Anggota K : 2
    //Masukkan Nilai Anggota K : 3
    //Masukkan Nilai Anggota K : 4
    //Masukkan Nilai Anggota K : 5
    //K = {2,3,4,5}
    //
    //Jumlah Anggota Himpunan L : 5
    //Masukkan Nilai Anggota L : 3
    //Masukkan Nilai Anggota L : 4
    //Masukkan Nilai Anggota L : 5
    //Masukkan Nilai Anggota L : 6
    //Masukkan Nilai Anggota L : 7
    //L = {3,4,5,6,7}
    //
    //K irisan L adalah…
    //KnL = {3,4,5}
    //
    //K gabungan L adalah…
    //KuL = {2,3,4,5,6,7}
    //
    //–===THANK YOU FOR USING THIS PROGRAM===–
    //————=======FIN=======————-

  28. //Wintama Wahyu Wisesa
    //S1 TI 3J
    //09.11.3250

    #include
    #include
    #define MAX 50

    void main() {
    int i, j, Stat;
    int p, q, n, m;
    int W[MAX];
    int Z[MAX];
    int WnZ[MAX], WuZ[MAX];

    printf(“<>”);
    printf(“\n”);
    printf(“\n”);

    n = 0;
    printf(“Insert Elements W : “);
    scanf(“%d”, &n);
    for(i = 0; i < n; i++) {
    printf("Point : ");
    scanf("%d", &W[i]);
    }
    printf("W = {%i", W[0]);
    for(i = 1; i < n; i++) {
    printf(",%d", W[i]);
    }
    printf("}\n");
    printf("\n");

    m = 0;
    printf("Insert Elements Z : ");
    scanf("%d", &m);
    for(i = 0; i < m; i++) {
    printf("Point : ");
    scanf("%d", &Z[i]);
    }
    printf("Z = {%i", Z[0]);
    for(i = 1; i < m; i++) {
    printf(",%d", Z[i]);
    }
    printf("}\n");
    printf("\n");

    p = 0;
    for(i = 0; i < n; i++) {
    for(j = 0; j < m; j++) {
    if(W[i] == Z[j]) {
    WnZ[p] = Z[j];
    p = p + 1;
    }
    }
    }
    printf("So W n Z :\n");
    printf("W n Z = {%d", WnZ[0]);
    for(i = 1; i < p; i++) {
    printf(",%d", WnZ[i]);
    }
    printf("}\n");
    printf("\n");

    Stat = 0;
    q = n;
    for(i = 0; i < n; i++) {
    WuZ[i] = W[i];
    }
    for(j = 0; j < m; j++) {
    Stat = 0;
    for(i = 0; i < n; i++) {
    if(Z[j] == W[i]) {
    Stat = 1;
    }
    }

    if(Stat == 0) {
    WuZ[q] = Z[j];
    q = q + 1;
    }
    }
    
    printf("So W u Z :\n");
    printf("W u Z = {%d", WuZ[0]);
    for(i = 1; i < q; i++) {
    printf(",%d", WuZ[i]);
    }
    printf("}\n");
    printf("\n");
    printf("<>”);

    getch();
    }

    //<>
    //Insert Element W : 3
    //Point : 2
    //Point : 1
    //Point : 2
    //W =

    //Insert Element Z : 4
    //Point : 2
    //Point : 1
    //Point : 3
    //Point : 4
    //Z =

    //So W n Z :
    //W n Z =

    //So W u Z :
    //W u Z =
    //<>

  29. //Titis Dwi Aribowo
    //09.11.3306
    //S1 TI 3J

    #include
    #include
    #define MAX 40

    void main() {
    int i, j, Stat;
    int p, q, n, m;
    int X[MAX];
    int Y[MAX];
    int XnY[MAX], XuY[MAX];

    n = 0;
    printf(“Banyak Himpunan X : “);
    scanf(“%d”, &n);
    for(i = 0; i < n; i++) {
    printf("Isi Nilai : ");
    scanf("%d", &X[i]);
    }
    printf("X = {%i", X[0]);
    for(i = 1; i < n; i++) {
    printf(",%d", X[i]);
    }
    printf("}\n");

    m = 0;
    printf("Banyak Himpunan Y : ");
    scanf("%d", &m);
    for(i = 0; i < m; i++) {
    printf("Isi Nilai : ");
    scanf("%d", &Y[i]);
    }
    printf("Y = {%i", Y[0]);
    for(i = 1; i < m; i++) {
    printf(",%d", Y[i]);
    }
    printf("}\n");

    p = 0;
    for(i = 0; i < n; i++) {
    for(j = 0; j < m; j++) {
    if(X[i] == Y[j]) {
    XnY[p] = Y[j];
    p = p + 1;
    }
    }
    }
    printf("Maka X irisan Y adalah…\n");
    printf("XnY = {%d", XnY[0]);
    for(i = 1; i < p; i++) {
    printf(",%d", XnY[i]);
    }
    printf("}\n");

    Stat = 0;
    q = n;
    for(i = 0; i < n; i++) {
    XuY[i] = X[i];
    }
    for(j = 0; j < m; j++) {
    Stat = 0;
    for(i = 0; i < n; i++) {
    if(Y[j] == X[i]) {
    Stat = 1;
    }
    }

    if(Stat == 0) {
    XuY[q] = Y[j];
    q = q + 1;
    }
    }

    printf("Maka X gabung Y adalah…\n");
    printf("XuY = {%d", XuY[0]);
    for(i = 1; i < q; i++) {
    printf(",%d", XuY[i]);
    }
    printf("}\n");

    getch();
    }
    //Banyak Himpunan X = 3
    //Isi Nilai = 1
    //Isi Nilai = 2
    //Isi Nilai = 3
    //X =
    //Banyak Himpunan Y = 4
    //Isi Nilai = 2
    //Isi Nilai = 4
    //Isi Nilai = 5
    //Isi Nilai = 6
    //Y =
    //Maka X irisan Y adalah. . .
    //XnY =
    //Maka X gabung Y adalah. . .
    //XuY =

  30. /*
    * PROGRAM HIMPUNAN
    *
    * NAMA : Ahmad Mufid
    * NIM : 09.11.3307
    * KELAS : S1TI-3J
    *
    * STMIK AMIKOM YOGYAKARTA
    *
    *
    * filename : himpunan.cpp
    *
    * editor : geany
    * compiler : g++
    * os : ubuntu 10.04 a.k.a lucid lynx
    *
    */
    #include // load library i/o
    #include // load library STL (Standard Template Library)
    #include // load library iterator

    using namespace std;

    int main() {
    const int MAX = 100; // definisikan maksimal anggota himpunan = 100
    int nA, nB, nU; // deklarasikan variabel nA = n|A|, nB = n|B|, nU = n|U|
    int himpunanA[MAX]; // deklarasikan array himpunanA
    int himpunanB[MAX]; // deklarasikan array himpunanB
    int himpunanU[MAX]; // deklarasikan array himpunanU = Universal

    // intro
    cout << "\n PROGRAM HIMPUNAN\n\n Nama\t: Ahmad Mufid\n NIM\t: 09.11.3307\n Kelas\t: S1TI-3J\n\n STMIK AMIKOM YOGYAKARTA\n";
    cout << "—————————————–\n";
    // masukkan jumlah anggota
    cout <> nU;
    cout <> nA;
    // cek apakah n|A| > n|U|
    // jika benar maka terjadi error, dan pengguna diminta untuk memasukkan ulang nilai n|A|
    if(nA > nU){
    cout <> nA;
    }
    cout <> nB;
    // cek apakah n|B| > n|U|
    // jika benar maka terjadi error, dan pengguna diminta untuk memasukkan ulang nilai n|B|
    if(nB > nU){
    cout <> nB;
    }

    cout << "\n HIMPUNAN UNIVERSAL : \n";
    // masukkan nilai dari masing-masing elemen himpunan Universal
    for (int i=0; i<nU; i++){
    cout << " Masukkan anggota Himpunan Universal ke-" << i+1 <> himpunanU[i];
    }

    cout << "\n HIMPUNAN A : \n";

    // masukkan nilai dari masing-masing elemen himpunan A
    for (int i=0; i<nA; i++){
    cout << " Masukkan anggota Himpunan A ke-" << i+1 <> himpunanA[i];
    }

    cout << "\n HIMPUNAN B : \n";
    // masukkan nilai dari masing-masing elemen himpunan B
    for (int i=0; i<nB; i++){
    cout << " Masukkan anggota Himpunan B ke-" << i+1 <> himpunanB[i];
    }
    cout << "\n—————————————–\n DATA YANG DIMASUKKAN";
    cout << "\n—————————————–\n";

    cout << "\n HIMPUNAN U \t: ";
    for(int i=0; i<nU; i++)
    cout << himpunanU[i] << " ";
    cout << "\n HIMPUNAN A \t: ";
    for(int i=0; i<nA; i++)
    cout << himpunanA[i] << " ";
    cout << "\n HIMPUNAN B \t: ";
    for(int i=0; i<nB; i++)
    cout << himpunanB[i] << " ";

    cout << "\n\n—————————————–\n OUTPUT";
    cout << "\n—————————————–\n\n";

    // panggil fungsi set_intersection dari library algorithm (STL)
    // fungsi ini akan menghasilkan irisan (intersection) dari himpunan A dan himpunan B
    // hasil intersection berupa iterator
    cout << " A INTERSECTION B \t: ";
    set_intersection(himpunanA, himpunanA+nA, himpunanB, himpunanB+nB, ostream_iterator(cout, ” “));

    // panggil fungsi set_difference dari library algorithm (STL)
    // fungsi ini akan menghasilkan difference dari himpunan A dan himpunan B
    // hasil difference berupa iterator
    cout << "\n\n A DIFFERENCE B \t: ";
    set_difference(himpunanA, himpunanA+nA, himpunanB, himpunanB+nB, ostream_iterator(cout, ” “));

    cout << "\n\n B DIFFERENCE A \t: ";
    set_difference(himpunanB, himpunanB+nB, himpunanA, himpunanA+nA, ostream_iterator(cout, ” “));

    // panggil fungsi set_union dari library algorithm (STL)
    // fungsi ini akan menghasilkan gabungan (union) dari himpunan A dan himpunan B
    // hasil union berupa iterator
    cout << "\n\n A UNION B \t\t: ";
    set_union(himpunanA, himpunanA+nA, himpunanB, himpunanB+nB, ostream_iterator(cout, ” “));

    // karena Complement A = U difference A, maka untuk mencari Complement A dapat menggunakan fungsi set_difference
    cout << "\n\n COMPLEMENT A \t\t: ";
    set_difference(himpunanU, himpunanU+nU, himpunanA, himpunanA+nA, ostream_iterator(cout, ” “));

    // karena Complement B = U difference B, maka untuk mencari Complement B dapat menggunakan fungsi set_difference
    cout << "\n\n COMPLEMENT B \t\t: ";
    set_difference(himpunanU, himpunanU+nU, himpunanB, himpunanB+nB, ostream_iterator(cout, ” “));

    cout << "\n\n—————————————–\n\n";

    return 0;

    }

  31. #include
    #include
    #define MAX 50

    void main() {
    int i, j, Stat;
    int p, q, n, m;
    int A[MAX];
    int B[MAX];
    int AnB[MAX], AuB[MAX];

    n = 0;
    printf(“Masukan Banyak Himpunan A : “);
    scanf(“%d”, &n);
    for(i = 0; i < n; i++) {
    printf("Isi Nilai : ");
    scanf("%d", &A[i]);
    }
    printf("A = {%i", A[0]);
    for(i = 1; i < n; i++) {
    printf(",%d", A[i]);
    }
    printf("}\n");

    m = 0;
    printf("Masukan Banyak Himpunan B : ");
    scanf("%d", &m);
    for(i = 0; i < m; i++) {
    printf("Isi Nilai : ");
    scanf("%d", &B[i]);
    }
    printf("B = {%i", B[0]);
    for(i = 1; i < m; i++) {
    printf(",%d", B[i]);
    }
    printf("}\n");

    p = 0;
    for(i = 0; i < n; i++) {
    for(j = 0; j < m; j++) {
    if(A[i] == B[j]) {
    AnB[p] = B[j];
    p = p + 1;
    }
    }
    }
    printf("Maka A irisan B adalah…\n");
    printf("AnB = {%d", AnB[0]);
    for(i = 1; i < p; i++) {
    printf(",%d", AnB[i]);
    }
    printf("}\n");

    Stat = 0;
    q = n;
    for(i = 0; i < n; i++) {
    AuB[i] = A[i];
    }
    for(j = 0; j < m; j++) {
    Stat = 0;
    for(i = 0; i < n; i++) {
    if(B[j] == A[i]) {
    Stat = 1;
    }
    }

    if(Stat == 0) {
    AuB[q] = B[j];
    q = q + 1;
    }
    }

    printf("Maka A gabung B adalah…\n");
    printf("AuB = {%d", AuB[0]);
    for(i = 1; i < q; i++) {
    printf(",%d", AuB[i]);
    }
    printf("}\n");

    getch();
    }

  32. //Muhammad Anwar )09.11.3253)
    //S1TI-3J

    import java.io.*;
    import java.util.*;

    public class SumOfSubsets
    {
    static int [] w;
    static int [] x;

    public static BufferedReader br =new BufferedReader(new InputStreamReader(System.in));

    public static void SumOfSubsets(int s, int k, int r, int m)
    {
    int i;
    x[k]=1;
    if((s+w[k])==m)
    {
    System.out.print(“{“);
    for(i=1;i<=k;i++) System.out.print(x[i]+" ");
    System.out.print("}\t");
    }
    else if((s+w[k]+w[k+1])=m)&&((s+w[k+1])<=m))
    {
    x[k]=0;
    SumOfSubsets(s,k+1,r-w[k],m);
    }
    }
    public static void main(String[] args) throws IOException
    {
    int i,j,temp,ord,max,sum=0;
    System.out.println("\t\t\t\tSUM OF SUBSETS");

    System.out.print("\n\nEnter the order of the set: ");
    ord = Integer.parseInt(br.readLine());

    w = new int[ord+1];
    x = new int[ord+1];

    System.out.println("\n\nEnter the elements of the set:");
    for(i=1;i<=ord;i++)
    {
    System.out.print("Element #"+i+": ");
    w[i] = Integer.parseInt(br.readLine());
    sum+=w[i];
    }

    System.out.println("\nEnter the sum to be made: ");
    max = Integer.parseInt(br.readLine());

    Arrays.sort(w, 1, w.length);

    if((max<w[1])||(sum < max))
    System.out.print("Sorry, Subsets can't be formed.");
    else
    {
    System.out.print("\nGiven set: \n{");
    for(i=1;i<=ord;System.out.print(w[i]+" "),i++);
    System.out.print("}");
    System.out.println("\n\nSubsets formed with sum as "+max+": ");
    SumOfSubsets.SumOfSubsets(0,1,sum,max);
    }
    }
    }


  33. /*
    * TUGAS MATIMATIKA DISKRIT
    * PROGRAM HIMPUNAN
    *
    * NAMA : AGUS SETIAWAN
    * NIM : 09.11.3298
    * KELAS : S1TI-3J
    *
    * STMIK AMIKOM YOGYAKARTA
    */
    #include // load library i/o
    #include // load library STL (Standard Template Library)
    #include // load library iterator
    #include

    using namespace std;

    int main() {
    const int MAX = 100; // definisikan maksimal anggota himpunan = 100
    int nA, nB, nU; // deklarasikan variabel nA = n|A|, nB = n|B|, nU = n|U|
    int himpunanA[MAX]; // deklarasikan array himpunanA
    int himpunanB[MAX]; // deklarasikan array himpunanB
    int himpunanU[MAX]; // deklarasikan array himpunanU = Universal

    // intro
    cout << "\n PROGRAM HIMPUNAN\n\n Nama\t: Agus Setiawan\n NIM\t: 09.11.3298\n Kelas\t: S1TI-3J\n\n STMIK AMIKOM YOGYAKARTA\n";
    cout << "—————————————–\n";
    // masukkan jumlah anggota
    cout <> nU;
    cout <> nA;
    // cek apakah n|A| > n|U|
    // jika benar maka terjadi error, dan pengguna diminta untuk memasukkan ulang nilai n|A|
    if(nA > nU){
    cout <> nA;
    }
    cout <> nB;
    // cek apakah n|B| > n|U|
    // jika benar maka terjadi error, dan pengguna diminta untuk memasukkan ulang nilai n|B|
    if(nB > nU){
    cout <> nB;
    }

    cout << "\n HIMPUNAN UNIVERSAL : \n";
    // masukkan nilai dari masing-masing elemen himpunan Universal
    for (int i=0; i<nU; i++){
    cout << " Masukkan anggota Himpunan Universal ke-" << i+1 <> himpunanU[i];
    }

    cout << "\n HIMPUNAN A : \n";

    // masukkan nilai dari masing-masing elemen himpunan A
    for (int i=0; i<nA; i++){
    cout << " Masukkan anggota Himpunan A ke-" << i+1 <> himpunanA[i];
    }

    cout << "\n HIMPUNAN B : \n";
    // masukkan nilai dari masing-masing elemen himpunan B
    for (int i=0; i<nB; i++){
    cout << " Masukkan anggota Himpunan B ke-" << i+1 <> himpunanB[i];
    }
    cout << "\n—————————————–\n DATA YANG DIMASUKKAN";
    cout << "\n—————————————–\n";

    cout << "\n HIMPUNAN U \t: ";
    for(int i=0; i<nU; i++)
    cout << himpunanU[i] << " ";
    cout << "\n HIMPUNAN A \t: ";
    for(int i=0; i<nA; i++)
    cout << himpunanA[i] << " ";
    cout << "\n HIMPUNAN B \t: ";
    for(int i=0; i<nB; i++)
    cout << himpunanB[i] << " ";

    cout << "\n\n—————————————–\n OUTPUT";
    cout << "\n—————————————–\n\n";

    // panggil fungsi set_intersection dari library algorithm (STL)
    // fungsi ini akan menghasilkan irisan (intersection) dari himpunan A dan himpunan B
    // hasil intersection berupa iterator
    cout << " A INTERSECTION B \t: ";
    set_intersection(himpunanA, himpunanA+nA, himpunanB, himpunanB+nB, ostream_iterator(cout, ” “));

    // panggil fungsi set_difference dari library algorithm (STL)
    // fungsi ini akan menghasilkan difference dari himpunan A dan himpunan B
    // hasil difference berupa iterator
    cout << "\n\n A DIFFERENCE B \t: ";
    set_difference(himpunanA, himpunanA+nA, himpunanB, himpunanB+nB, ostream_iterator(cout, ” “));

    cout << "\n\n B DIFFERENCE A \t: ";
    set_difference(himpunanB, himpunanB+nB, himpunanA, himpunanA+nA, ostream_iterator(cout, ” “));

    // panggil fungsi set_union dari library algorithm (STL)
    // fungsi ini akan menghasilkan gabungan (union) dari himpunan A dan himpunan B
    // hasil union berupa iterator
    cout << "\n\n A UNION B \t\t: ";
    set_union(himpunanA, himpunanA+nA, himpunanB, himpunanB+nB, ostream_iterator(cout, ” “));

    // karena Complement A = U difference A, maka untuk mencari Complement A dapat menggunakan fungsi set_difference
    cout << "\n\n COMPLEMENT A \t\t: ";
    set_difference(himpunanU, himpunanU+nU, himpunanA, himpunanA+nA, ostream_iterator(cout, ” “));

    // karena Complement B = U difference B, maka untuk mencari Complement B dapat menggunakan fungsi set_difference
    cout << "\n\n COMPLEMENT B \t\t: ";
    set_difference(himpunanU, himpunanU+nU, himpunanB, himpunanB+nB, ostream_iterator(cout, ” “));

    cout << "\n\n—————————————–\n\n";
    getch();

    return 0;

    }

  34. //Nama : Sigit joko Nugroho
    //Kelas : S1.TI.3J
    //NIM : 09.11.3283

    package DiskretHimpunan;

    public class Main {
    public static void main(String[] args) {

    //Deklarasi variabel
    int[] X, Y, Irisan, Gabungan, BedaSetangkup, SelisihAB, SelisihBA;
    int i, j, k, l, m, n, p, q, r, tmp;

    //Instantiasi objek
    X= new int [50];
    Y= new int [50];
    Irisan= new int [50];
    Gabungan= new int [50];
    BedaSetangkup= new int [50];
    SelisihAB= new int [50];
    SelisihBA= new int [50];

    System.out.println(“”);
    System.out.println(“Aplikasi Operasi Himpunan Dari Himpunan A dan B”);
    System.out.println(“———————————————————-“);

    //Input Himpunan A
    m = 0;
    System.out.print(“Jumlah elemen Himpunan A : “);
    m = Integer.parseInt(System.console().readLine());
    for(i = 0; i < m; i++) {
    System.out.print("Input elemen A : ");
    X[i]=Integer.parseInt(System.console().readLine());
    }

    //Menampilkan Himpunan A
    System.out.print("A = {"+X[0]);
    for(i = 1; i < m; i++) {
    System.out.print("," + X[i]);
    }
    System.out.print("}\n");
    System.out.println("");

    //Input Himpunan B
    n = 0;
    System.out.print("Jumlah elemen Himpunan B : ");
    n = Integer.parseInt(System.console().readLine());
    for(i = 0; i < n; i++) {
    System.out.print("Input elemen B : ");
    Y[i]=Integer.parseInt(System.console().readLine());
    }

    //Menampilkan Himpunan B
    System.out.print("B = {" + Y[0]);
    for(i = 1; i < n; i++) {
    System.out.print("," + Y[i]);
    }
    System.out.print("}\n");
    System.out.println("");

    //Proses Pencarian Irisan
    k = 0;
    for(i = 0; i < m; i++) {
    for(j = 0; j < n; j++) {
    if(X[i] == Y[j]) {
    Irisan[k] = Y[j];
    k = k + 1;
    }
    }
    }
    //Menampilkan Irisan Himpunan
    System.out.println("———————————————————-");
    System.out.print("Jadi A irisan B adalah\n");
    System.out.print("AnB = {"+ Irisan[0]);
    for(i = 1; i < k; i++) {
    System.out.print(","+ Irisan[i]);
    }
    System.out.print("}\n");
    System.out.println("");

    //Proses Penggabungan Himpunan
    tmp = 0;
    l = m;
    for(i = 0; i < m; i++) {
    Gabungan[i] = X[i];
    }

    for(j = 0; j < n; j++) {
    tmp = 0;
    for(i = 0; i < m; i++) {
    if(Y[j] == X[i]) {
    tmp = 1;
    }
    }

    if(tmp == 0) {
    Gabungan[l] = Y[j];
    l = l + 1;
    }
    }
    //Menampilkan Gabungan Himpunan
    System.out.print("Jadi A gabung B adalah\n");
    System.out.print("AuB = {"+ Gabungan[0]);
    for(i = 1; i < l; i++) {
    System.out.print(","+Gabungan[i]);
    }
    System.out.print("}\n");
    System.out.println("");

    //Proses Selisih A-B
    q = 0;
    for (i = 0; i < m; i++){
    tmp = 0;
    for(j = 0; j < n; j++) {
    if( X[i] == Y[j]) {
    tmp = 1;
    }
    }

    if(tmp == 0) {
    SelisihAB[q] = X[i];
    q = q + 1;
    }
    }
    //Menampilkan Selisih Himpunan A-B
    System.out.print("Jadi Selisih A – B adalah\n");
    System.out.print("(A-B) = {"+ SelisihAB[0]);
    for(i = 1; i < q; i++) {
    System.out.print(","+SelisihAB[i]);
    }
    System.out.print("}\n");
    System.out.println("");

    //Proses Selisih B-A
    r=0;
    for(j = 0; j < n; j++) {
    tmp = 0;
    for(i = 0; i < m; i++) {
    if(Y[j] == X[i]) {
    tmp = 1;
    }
    }

    if(tmp == 0) {
    SelisihBA[r] = Y[j];
    r = r + 1;
    }
    }
    //Menampilkan Selisih Himpunan A-B
    System.out.print("Jadi Selisih B – A adalah\n");
    System.out.print("(B-A) = {"+ SelisihBA[0]);
    for(i = 1; i < r; i++) {
    System.out.print(","+SelisihBA[i]);
    }
    System.out.print("}\n");
    System.out.println("");

    //Proses Pencarian Beda Setangkup/Symmetric Different
    p = 0;
    for (i = 0; i < m; i++){
    tmp = 0;
    for(j = 0; j < n; j++) {
    if( X[i] == Y[j]) {
    tmp = 1;
    }
    }

    if(tmp == 0) {
    BedaSetangkup[p] = X[i];
    p = p + 1;
    }
    }

    for(j = 0; j < n; j++) {
    tmp = 0;
    for(i = 0; i < m; i++) {
    if(Y[j] == X[i]) {
    tmp = 1;
    }
    }

    if(tmp == 0) {
    BedaSetangkup[p] = Y[j];
    p = p + 1;
    }
    }
    //Menampilkan Beda Setangkup Himpunan
    System.out.print("Jadi Beda Setangkup A dan B adalah\n");
    System.out.print("(A-B)u(B-A) = {"+ BedaSetangkup[0]);
    for(i = 1; i < p; i++) {
    System.out.print(","+BedaSetangkup[i]);
    }
    System.out.print("}\n");
    System.out.println("———————————————————-");
    }
    }

    /*
    Output Tampilan

    Aplikasi Operasi Himpunan Dari Himpunan A dan B
    ———————————————————-
    Jumlah elemen Himpunan A : 4
    Input elemen A : 2
    Input elemen A : 3
    Input elemen A : 5
    Input elemen A : 7
    A = {2,3,5,7}
    Jumlah elemen Himpunan B : 5
    Input elemen B : 1
    Input elemen B : 2
    Input elemen B : 3
    Input elemen B : 4
    Input elemen B : 5
    B = {1,2,3,4,5}
    ———————————————————-
    Jadi A irisan B adalah
    AnB = {2,3,5}
    Jadi A gabung B adalah
    AuB = {2,3,5,7,1,4}
    Jadi Selisih A – B adalah
    (A-B) = {7}
    Jadi Selisih B – A adalah
    (B-A) = {1,4}
    Jadi Beda Setangkup A dan B adalah
    (A-B)u(B-A) = {1,4,7}
    ———————————————————-
    */

  35. MATEMATIKA DISKRIT

    NAMA : FERY BELLY YOGA PRASATYA
    NIM : 09.11.3268
    KELAS : S1-TI-3J

    PROGRAM JAVA HIMPUNAN GABUNGAN DAN IRISAN
    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    package himpunan;
    import javax.swing.JOptionPane;

    /**
    *
    * @author Fery_Gokil
    */
    public class CLSHIMPUNAN {
    public int []gabung(int []a,int []b) {

    int []temp = new int[a.length + b.length];
    int n = 0;

    // copy semua nilai a ke temp
    for(int i=0;i<a.length;i++)
    temp[n++] = a[i];

    // copy semua nilai b yang tidak ada di a
    for(int i=0;i<b.length;i++) {
    boolean ada = false;
    for(int j=0;j<a.length && !ada;j++)
    if(a[j]==b[i]) ada = true;

    // jika tidak ada baru kita copy
    if(!ada) temp[n++] = b[i];
    }

    // copy nilai temp ke ret
    int []ret = new int[n];
    System.arraycopy(temp, 0, ret, 0, n);

    return ret;
    }

    //method/function gabungan
    public int []irisan(int []a,int []b) {
    int []temp = new int[b.length];
    int n = 0;

    // copy semua nilai b yang ada di a
    for(int i=0;i<b.length;i++) {
    boolean ada = false;
    for(int j=0;j<a.length && !ada;j++)
    if(a[j]==b[i]) ada = true;

    // jika ada baru kita copy
    if(ada) temp[n++] = b[i];
    }

    // copy nilai temp ke ret
    int []ret = new int[n];
    System.arraycopy(temp, 0, ret, 0, n);

    return ret;
    }
    public static void main(String[] args) {
    clsTes tes = new clsTes();

    String tmp;
    int x, y;

    tmp = JOptionPane.showInputDialog("Masukkan banyak anggota A");
    x = Integer.parseInt(tmp);

    int [] A;
    A = new int[x];
    //minta inputan
    for (int i = 0; i < x; i++) {
    A[i] = Integer.parseInt(JOptionPane.showInputDialog("Masukkan anggota " +
    "ke – " + (i+1)));

    }

    tmp = JOptionPane.showInputDialog("Masukkan banyak anggota B");
    y = Integer.parseInt(tmp);

    int [] B;
    B = new int[y];
    //minta inputan untuk B
    for (int i = 0; i < y; i++) {
    B[i] = Integer.parseInt(JOptionPane.showInputDialog("Masukkan anggota " +
    "ke – " + (i+1)));

    }
    //tampilkan anggota Himpunan A
    System.out.println("Anggota Himpunan A");
    for (int i = 0; i < x; i++) {
    System.out.print(A[i] + ",");
    }
    System.out.println("");

    System.out.println("Anggota Himpunan B");
    for (int i = 0; i < y; i++) {
    System.out.print(B[i] + ",");
    }
    System.out.println("");

    int g[] = tes.gabung(A, B);
    int I[] = tes.irisan(A, B);

    System.out.println("Hasil Gabungan :");
    for (int i = 0; i < g.length; i++) {
    System.out.print(g[i] + ",");

    }
    System.out.println("");

    System.out.println("Hasil Irisan :");
    for (int i = 0; i < I.length; i++) {
    System.out.print(I[i] + ",");
    }
    System.out.println("");

    }

    }
    //HASIL
    run:
    //INPUT
    Anggota Himpunan A
    1,2,
    Anggota Himpunan B
    1,2,3,4,

    //OUTPUT
    Hasil Gabungan :
    1,2,3,4,
    Hasil Irisan :
    1,2,
    BUILD SUCCESSFUL (total time: 17 seconds)

  36. #include
    #include
    #define MAX 50

    void main() {
    int i, j, Stat;
    int p, q, n, m;
    int A[MAX];
    int B[MAX];
    int AnB[MAX], AuB[MAX];

    n = 0;
    printf(” Program Mencari Irisan dan Gabungan Himpunan \n”);
    printf(“\nMasukan panjang Himpunan A : “);
    scanf(“%d”, &n);
    for(i = 0; i < n; i++) {
    printf("Masukkan Nilai : ");
    scanf("%d", &A[i]);
    }
    printf("A = {%i", A[0]);
    for(i = 1; i < n; i++) {
    printf(",%d", A[i]);
    }
    printf("}\n");

    m = 0;
    printf("Masukan panjang Himpunan B : ");
    scanf("%d", &m);
    for(i = 0; i < m; i++) {
    printf("Masukkan Nilai : ");
    scanf("%d", &B[i]);
    }
    printf("B = {%i", B[0]);
    for(i = 1; i < m; i++) {
    printf(",%d", B[i]);
    }
    printf("}\n");

    p = 0;
    for(i = 0; i < n; i++) {
    for(j = 0; j < m; j++) {
    if(A[i] == B[j]) {
    AnB[p] = B[j];
    p = p + 1;
    }
    }
    }
    printf("Maka A irisan B adalah…\n");
    printf("AnB = {%d", AnB[0]);
    for(i = 1; i < p; i++) {
    printf(",%d", AnB[i]);
    }
    printf("}\n");

    Stat = 0;
    q = n;
    for(i = 0; i < n; i++) {
    AuB[i] = A[i];
    }
    for(j = 0; j < m; j++) {
    Stat = 0;
    for(i = 0; i < n; i++) {
    if(B[j] == A[i]) {
    Stat = 1;
    }
    }

    if(Stat == 0) {
    AuB[q] = B[j];
    q = q + 1;
    }
    }

    printf("Maka A gabung B adalah…\n");
    printf("AuB = {%d", AuB[0]);
    for(i = 1; i < q; i++) {
    printf(",%d", AuB[i]);
    }
    printf("}\n");

    getch();
    }

  37. Darma Putra Hadinata (09.11.3269)

    package apptesthimp;

    public class Main {
    public static void main(String[] args) {
    int[] A, B;
    int[] AnB, AuB;
    int n, m;

    System.out.print(“Masukan Jumlah Himpunan A : “);
    n = Integer.parseInt(System.console().readLine());
    System.out.print(“Masukan Jumlah Himpunan B : “);
    m = Integer.parseInt(System.console().readLine());

    A = new
    System.out.println(“Masukan Himp A : “);
    System.console().readLine();
    }
    }

  38. /*
    Nama : Nurul Farida
    NIM : 09.11.3242
    Kelas :S1TI-3j

    */

    #include
    #include

    int himpunan1[50];
    int himpunan2[50];
    int i,j,jml1,jml2,l;
    int irisan[50], union1[50];
    bool sama;

    void main(){
    cout<<"=== Masukkan data himpunan pertama ===\n"<<endl;
    cout<>jml1;
    for (i=1;i<=jml1;i++){
    cout<<"Data "<<i<>himpunan1[i];
    }
    cout<<"himpunan pertama adalah ";
    cout<<"{";
    for(i=1;i<=jml1;i++){
    cout<<himpunan1[i]<<", ";
    }
    cout<<"}\n";

    cout<<"\n === Masukkan data himpunan kedua ===\n"<<endl;
    cout<>jml2;
    for (j=1;j<=jml2;j++){
    cout<<"Data "<<j<>himpunan2[j];
    }
    cout<<"himpunan kedua adalah ";
    cout<<"{";
    for (j=1;j<=jml2;j++){
    cout<<himpunan2[j]<<", ";
    }cout<<"}\n";

    cout<<"\n 1.) Irisan dari kedua himpunan tersebut adalah ";
    cout<<"{";
    l=0;
    for (i=1;i<=jml1;i++){
    for (j=1;j<=jml2;j++){
    if (himpunan1[i]==himpunan2[j]){
    l=l+1;
     irisan[l]=himpunan2[j];
    cout<<irisan[l]<<", ";
    }
    }
    } cout<<"}";

    cout<<"\n\n 2.) Gabungan dari kedua himpunan tersebut adalah ";
    // perintah gabungan
    cout<<"{";
    for (i=1;i<=jml1;i++){
    union1[i]=himpunan1[i];
    cout<<union1[i]<<", ";
    }
    for (i=1;i<=jml2;i++){
    sama=false;
    for (j=1;j<=jml1;j++){
    if (himpunan2[i]== himpunan1[j]){
    sama=true;
    }
    }
    if (!sama){
    union1[i+jml1]=himpunan2[i];
    cout<<union1[i+jml1]<<", ";
    }
    } cout<<"} ";

    getch(); }

  39. #include
    #include
    #define MAX 50

    void main() {
    int i, j, Stat;
    int p, q, n, m;
    int A[MAX];
    int B[MAX];
    int AnB[MAX], AuB[MAX];

    n = 0;
    printf(” program Irisan dan Gabungan \n”);
    printf(“Masukan banyak Himpunan Z : “);
    scanf(“%d”, &n);
    for(i = 0; i < n; i++) {
    printf("Isi Nilai : ");
    scanf("%d", &A[i]);
    }
    printf("A = {%i", A[0]);
    for(i = 1; i < n; i++) {
    printf(",%d", A[i]);
    }
    printf("}\n");

    m = 0;
    printf("Masukan Banyak Himpunan B : ");
    scanf("%d", &m);
    for(i = 0; i < m; i++) {
    printf("Isi Nilai : ");
    scanf("%d", &B[i]);
    }
    printf("B = {%i", B[0]);
    for(i = 1; i < m; i++) {
    printf(",%d", B[i]);
    }
    printf("}\n");

    p = 0;
    for(i = 0; i < n; i++) {
    for(j = 0; j < m; j++) {
    if(A[i] == B[j]) {
    AnB[p] = B[j];
    p = p + 1;
    }
    }
    }
    printf("Jadi A irisan B adalah…\n");
    printf("AnB = {%d", AnB[0]);
    for(i = 1; i < p; i++) {
    printf(",%d", AnB[i]);
    }
    printf("}\n");

    Stat = 0;
    q = n;
    for(i = 0; i < n; i++) {
    AuB[i] = A[i];
    }
    for(j = 0; j < m; j++) {
    Stat = 0;
    for(i = 0; i < n; i++) {
    if(B[j] == A[i]) {
    Stat = 1;
    }
    }

    if(Stat == 0) {
    AuB[q] = B[j];
    q = q + 1;
    }
    }

    printf("Jadi A gabung B adalah…\n");
    printf("AuB = {%d", AuB[0]);
    for(i = 1; i < q; i++) {
    printf(",%d", AuB[i]);
    }
    printf("}\n");

    getch();
    }

  40. #include
    #include
    #include
    #define MAX 50

    int i, j, Stat;
    int p, q, n, m;
    int A[MAX];
    int B[MAX];
    int AnB[MAX], AuB[MAX];
    char kembali;

    void himpunan_irisan(void)
    {

    n = 0;
    printf(“Masukan panjang Himpunan A : “);
    scanf(“%d”, &n);
    for(i = 0; i < n; i++) {
    printf("Isi Nilai : ");
    scanf("%d", &A[i]);
    }
    printf("A = {%i", A[0]);
    for(i = 1; i < n; i++) {
    printf(",%d", A[i]);
    }
    printf("}\n");

    m = 0;
    printf("Masukan panjang Himpunan B : ");
    scanf("%d", &m);
    for(i = 0; i < m; i++) {
    printf("Isi Nilai : ");
    scanf("%d", &B[i]);
    }
    printf("B = {%i", B[0]);
    for(i = 1; i < m; i++) {
    printf(",%d", B[i]);
    }
    printf("}\n");

    p = 0;
    for(i = 0; i < n; i++) {
    for(j = 0; j < m; j++) {
    if(A[i] == B[j]) {
    AnB[p] = B[j];
    p = p + 1;
    }
    }
    }
    printf("Maka A irisan B adalah…\n");
    printf("AnB = {%d", AnB[0]);
    for(i = 1; i < p; i++) {
    printf(",%d", AnB[i]);
    }
    printf("}\n");

    Stat = 0;
    q = n;
    for(i = 0; i < n; i++) {
    AuB[i] = A[i];
    }
    for(j = 0; j < m; j++) {
    Stat = 0;
    for(i = 0; i < n; i++) {
    if(B[j] == A[i]) {
    Stat = 1;
    }
    }

    if(Stat == 0) {
    AuB[q] = B[j];
    q = q + 1;
    }
    }
    getch();
    }
    void himpunan_gabungan(void)
    {
    n = 0;
    printf("Masukan banyaknya Himpunan A : ");
    scanf("%d", &n);
    for(i = 0; i < n; i++) {
    printf("Isi Nilai : ");
    scanf("%d", &A[i]);
    }
    printf("A = {%i", A[0]);
    for(i = 1; i < n; i++) {
    printf(",%d", A[i]);
    }
    printf("}\n");

    m = 0;
    printf("Masukan banyaknya Himpunan B : ");
    scanf("%d", &m);
    for(i = 0; i < m; i++) {
    printf("Isi Nilai : ");
    scanf("%d", &B[i]);
    }
    printf("B = {%i", B[0]);
    for(i = 1; i < m; i++) {
    printf(",%d", B[i]);
    }
    printf("}\n");

    Stat = 0;
    q = n;
    for(i = 0; i < n; i++) {
    AuB[i] = A[i];
    }
    for(j = 0; j < m; j++) {
    Stat = 0;
    for(i = 0; i < n; i++) {
    if(B[j] == A[i]) {
    Stat = 1;
    }
    }

    if(Stat == 0) {
    AuB[q] = B[j];
    q = q + 1;
    }
    }

    printf("Maka A gabung B adalah…\n");
    printf("AuB = {%d", AuB[0]);
    for(i = 1; i < q; i++) {
    printf(",%d", AuB[i]);
    }
    printf("}\n");
    getch();
    }

    void menu(void)
    {

    int pil1;

    printf(" =======Program untuk mencari himpunan=======\n");
    printf("\n");
    printf("1. mencari AuB..\n");
    printf("2. mencari AnB..\n");
    cout<<"Silahkan pilih (1/2)"<>pil1;
    clrscr();
    if (pil1==1)
    {
    himpunan_irisan();
    }
    else if (pil1==2)
    {
    himpunan_gabungan();
    }
    else
    {
    printf(“Masukan anda salah…\n”);

    }

    printf(“Apakah anda ingin kembali ke menu utama ? (y/n)\n”);
    scanf(“kembali”);
    clrscr();
    if (kembali==’y’||’Y’)
    {
    menu();
    }
    else if (kembali==’n’||’N’)
    {
    printf(“Terima kasih telah menggunakan program ini…\n”);
    }
    else
    {
    printf(“Masukkan anda salah…”);
    }

    }

    main()
    {
    menu();

    getch();
    }

  41. #include
    #include
    #define MAX 50

    void main() {
    int i, j, Stat;
    int p, q, n, m;
    int A[MAX];
    int B[MAX];
    int AnB[MAX], AuB[MAX];

    n = 0;
    printf(” Program Mencari Irisan dan Gabungan Himpunan \n”);
    printf(“\nMasukan panjang Himpunan A : “);
    scanf(“%d”, &n);
    for(i = 0; i < n; i++) {
    printf("Masukkan Nilai : ");
    scanf("%d", &A[i]);
    }
    printf("A = {%i", A[0]);
    for(i = 1; i < n; i++) {
    printf(",%d", A[i]);
    }
    printf("}\n");

    m = 0;
    printf("Masukan panjang Himpunan B : ");
    scanf("%d", &m);
    for(i = 0; i < m; i++) {
    printf("Masukkan Nilai : ");
    scanf("%d", &B[i]);
    }
    printf("B = {%i", B[0]);
    for(i = 1; i < m; i++) {
    printf(",%d", B[i]);
    }
    printf("}\n");

    p = 0;
    for(i = 0; i < n; i++) {
    for(j = 0; j < m; j++) {
    if(A[i] == B[j]) {
    AnB[p] = B[j];
    p = p + 1;
    }
    }
    }
    printf("Maka A irisan B adalah…\n");
    printf("AnB = {%d", AnB[0]);
    for(i = 1; i < p; i++) {
    printf(",%d", AnB[i]);
    }
    printf("}\n");

    Stat = 0;
    q = n;
    for(i = 0; i < n; i++) {
    AuB[i] = A[i];
    }
    for(j = 0; j < m; j++) {
    Stat = 0;
    for(i = 0; i < n; i++) {
    if(B[j] == A[i]) {
    Stat = 1;
    }
    }

    if(Stat == 0) {
    AuB[q] = B[j];
    q = q + 1;
    }
    }

    printf("Maka A gabung B adalah…\n");
    printf("AuB = {%d", AuB[0]);
    for(i = 1; i < q; i++) {
    printf(",%d", AuB[i]);
    }
    printf("}\n");

    getch();
    }

  42. NAMA : YUSTINA MAULANI
    NIM : 09.11.3288
    KELAS : S1 TI-3J

    #include
    #include
    #include
    #include
    int him1[100];
    int him2[100];
    char ulang;
    int i,j,jum1,jum2,t,pilih,l;
    int union1[100],irisan[100];
    bool sama;
    void main(){
    cout<<"\t\tMenu \n";
    cout<<"1. mencari union dari himpunan\n";
    cout<<"0. keluar\n";
    cout<"———————————–";
    cout<<endl;
    ulang='y';
    do
    {

    cout<<endl;
    cout<>pilih;
    switch (pilih)
    {
    case 1:
    cout<<"Program mencari union dari himpunan"<<endl;
    cout<<"masukkan data himpunan pertama!"<<endl;
    cout<>jum1;
    for (i=1;i<=jum1;i++){
    cout<<"data "<<i<>him1[i];
    }
    cout<<"himpunan pertama:";
    for (i=1;i<=jum1;i++){
    cout<<him1[i]<<" ";
    }
    cout<<endl;
    cout<<"masukkan data himpunan kedua!"<<endl;
    cout<>jum2;
    for (j=1;j<=jum2;j++){
    cout<<"data "<<j<>him2[j];
    }
    cout<<"himpunan kedua:";
    for (j=1;j<=jum2;j++){
    cout<<him2[j]<<" ";
    }
    cout<<endl;
    //perintah union
    cout<<"Union dari himpunan satu dan himpunan dua adalah:"<<endl;
    for (i=1;i<=jum1;i++){
    union1[i]=him1[i];
    cout<<union1[i]<<", ";
    }
    for (i=1;i<=jum2;i++){
    sama=false;
    for (j=1;j<=jum1;j++){
    if (him2[i]== him1[j]){
    sama=true;
    }

    }
    if (!sama){
    union1[i+jum1]=him2[i];
    cout<<union1[i+jum1]<<", ";
    }
    }
    break;
    case 0:ulang=='t';
    default:cout<<"bukan pilahan yang valid!";
    cout<<endl;
    cout<>ulang;
    }
    }while (ulang==’y’);
    }

    Hasil Compile :

    //komentar tidak bisa memuat gambar (hasil compile)

  43. #include
    #include
    #include
    #include
    int him1[100];
    int him2[100];
    char ulang;
    int i,j,jum1,jum2,t,pilih,l;
    int union1[100],irisan[100];
    bool sama;
    void main(){
    cout<<"\t\tMenu \n";
    cout<<"1. Mencari union pada himpunan\n";
    cout<<"0. Exite\n";
    cout<"———————————–";
    cout<<endl;
    ulang='Y';
    do
    {

    cout<<endl;
    cout<>pilih;
    switch (pilih)
    {
    case 1:
    cout<<"Program mencari union dari himpunan"<<endl;
    cout<<"Masukkan data pada himpunan pertama!"<<endl;
    cout<>jum1;
    for (i=1;i<=jum1;i++){
    cout<<"data "<<i<>him1[i];
    }
    cout<<"Himpunan pertama:";
    for (i=1;i<=jum1;i++){
    cout<<him1[i]<<" ";
    }
    cout<<endl;
    cout<<"Masukkan data pada himpunan kedua!"<<endl;
    cout<>jum2;
    for (j=1;j<=jum2;j++){
    cout<<"data "<<j<>him2[j];
    }
    cout<<"Himpunan kedua:";
    for (j=1;j<=jum2;j++){
    cout<<him2[j]<<" ";
    }
    cout<<endl;
    //PERINTAH UNION
    cout<<"Union pada himpunan satu dan himpunan dua adalah:"<<endl;
    for (i=1;i<=jum1;i++){
    union1[i]=him1[i];
    cout<<union1[i]<<", ";
    }
    for (i=1;i<=jum2;i++){
    sama=false;
    for (j=1;j<=jum1;j++){
    if (him2[i]== him1[j]){
    sama=true;
    }

    }
    if (!sama){
    union1[i+jum1]=him2[i];
    cout<<union1[i+jum1]<<", ";
    }
    }
    break;
    case 0:ulang=='t';
    default:cout<<"Bukan pilahan yang valid!";
    cout<<endl;
    cout<>ulang;
    }
    }while (ulang==’Y’);
    }

    Nama : Islin Tabuni
    NIM : 09.11.3241
    Kelas : S1TI3J

    hasil :
    hasil:
    menu
    1. mencari union pada himpunan
    0. exit
    masukkan angka: 1
    program mencari union pada himpunan
    masukkan data pada himpunan pertama :
    masukkan jumlah data:2
    data 1: 5
    data 2 : 36
    himpunan pertama : 5,6

    masuk data pada himpunan kedua :
    masukkan jumlah data : 2
    data 1: 3
    data 2: 9
    himpunan kedua : 3,9

    union dari himpuna pertama dan kedua : 5,6,9
    apakah anda ingin mengulang ? : n

  44. //Miftahul Jannah
    //Nim : 09/11/3257
    //Kelas : SITI-3J

    #include
    #include
    #include
    #include
    int him1[100];
    int him2[100];
    char ulang;
    int i,j,jum1,jum2,t,pilih,l;
    int union1[100],irisan[100];
    bool sama;
    void main(){
    cout<<"\t\tMenu \n";
    cout<<"1. Mencari Union Dari Himpunan\n";
    cout<<"2. Exit\n";
    cout<"———————————–";
    cout<<endl;
    ulang='y';
    do
    {

    cout<<endl;
    cout<>pilih;
    cout<<"\n";
    switch (pilih)
    {
    case 1:
    cout<<"–Program Mencari Union Dari Himpunan–"<<endl;
    cout<<"\n";
    cout<<"Masukkan Data Himpunan Pertama : "<<endl;
    cout<>jum1;
    for (i=1;i<=jum1;i++){
    cout<<"Data "<<i<>him1[i];
    }
    cout<<"Himpunan Pertama : ";
    for (i=1;i<=jum1;i++){
    cout<<him1[i]<<" ";
    }
    cout<<endl;
    cout<<"\n";
    cout<<"Masukkan Data Himpunan Kedua : "<<endl;
    cout<>jum2;
    for (j=1;j<=jum2;j++){
    cout<<"Data "<<j<>him2[j];
    }
    cout<<"Himpunan Kedua : ";
    for (j=1;j<=jum2;j++){
    cout<<him2[j]<<" ";
    }
    cout<<endl;
    cout<<"\n";
    //perintah union
    cout<<"Union Dari Himpunan Pertama Dan Himpunan Kedua Ialah : ";
    for (i=1;i<=jum1;i++){
    union1[i]=him1[i];
    cout<<union1[i]<<", ";
    }
    for (i=1;i<=jum2;i++){
    sama=false;
    for (j=1;j<=jum1;j++){
    if (him2[i]== him1[j]){
    sama=true;
    }

    }
    if (!sama){
    union1[i+jum1]=him2[i];
    cout<<union1[i+jum1]<<", ";
    }
    cout<<"\n";
    }
    break;
    case 0:ulang=='t';
    default:cout<<"Bukan Pilahan Yang Valid !!!";
    cout<<"\n";
    cout<<endl;
    cout<>ulang;
    }
    }while (ulang==’y’);
    }

    hasil:
    menu
    1. mencari union dari himpunan
    2. exit
    masukkan pilihan: 1
    –program mencari union dari himpunan–
    masukkan data himpinn pertama :
    input jumlah data:2
    data 1: 2
    data 2 : 3
    himpunan pertama : 2, 3

    masuk data himpynan kedua :
    input jumlah data : 2
    data 1: 3
    data 2: 4
    himpunan kedua : 3,4

    union dari himpuna pertama dan kedua : 2,3,4
    apakah anda ingin mengulang ? : n

  45. #include
    #include
    #define MAX 50

    void main() {
    int i, j, Stat;
    int p, q, n, m;
    int A[MAX];
    int B[MAX];
    int AnB[MAX], AuB[MAX];

    n = 0;
    printf(“Masukan panjang Himpunan A : “);
    scanf(“%d”, &n);
    for(i = 0; i < n; i++) {
    printf("Isi Nilai : ");
    scanf("%d", &A[i]);
    }
    printf("A = {%i", A[0]);
    for(i = 1; i < n; i++) {
    printf(",%d", A[i]);
    }
    printf("}\n");

    m = 0;
    printf("Masukan panjang Himpunan B : ");
    scanf("%d", &m);
    for(i = 0; i < m; i++) {
    printf("Isi Nilai : ");
    scanf("%d", &B[i]);
    }
    printf("B = {%i", B[0]);
    for(i = 1; i < m; i++) {
    printf(",%d", B[i]);
    }
    printf("}\n");

    p = 0;
    for(i = 0; i < n; i++) {
    for(j = 0; j < m; j++) {
    if(A[i] == B[j]) {
    AnB[p] = B[j];
    p = p + 1;
    }
    }
    }
    printf("Maka A irisan B adalah…\n");
    printf("AnB = {%d", AnB[0]);
    for(i = 1; i < p; i++) {
    printf(",%d", AnB[i]);
    }
    printf("}\n");

    Stat = 0;
    q = n;
    for(i = 0; i < n; i++) {
    AuB[i] = A[i];
    }
    for(j = 0; j < m; j++) {
    Stat = 0;
    for(i = 0; i < n; i++) {
    if(B[j] == A[i]) {
    Stat = 1;
    }
    }

    if(Stat == 0) {
    AuB[q] = B[j];
    q = q + 1;
    }
    }

    printf("Maka A gabung B adalah…\n");
    printf("AuB = {%d", AuB[0]);
    for(i = 1; i < q; i++) {
    printf(",%d", AuB[i]);
    }
    printf("}\n");

    getch();
    }

  46. #include
    #include
    #include
    #include
    int him1[100];
    int him2[100];
    char ulang;
    int i,j,jum1,jum2,t,pilih,l;
    int union1[100],irisan[100];
    bool sama;
    void main(){
    cout<<"\t\tMenu \n";
    cout<<"1. mencari union dari himpunan\n";
    cout<<"0. keluar\n";
    cout<"———————————–";
    cout<<endl;
    ulang='y';
    do
    {

    cout<<endl;
    cout<>pilih;
    switch (pilih)
    {
    case 1:
    cout<<"Program mencari union dari himpunan"<<endl;
    cout<<"masukkan data himpunan pertama!"<<endl;
    cout<>jum1;
    for (i=1;i<=jum1;i++){
    cout<<"data "<<i<>him1[i];
    }
    cout<<"himpunan pertama:";
    for (i=1;i<=jum1;i++){
    cout<<him1[i]<<" ";
    }
    cout<<endl;
    cout<<"masukkan data himpunan kedua!"<<endl;
    cout<>jum2;
    for (j=1;j<=jum2;j++){
    cout<<"data "<<j<>him2[j];
    }
    cout<<"himpunan kedua:";
    for (j=1;j<=jum2;j++){
    cout<<him2[j]<<" ";
    }
    cout<<endl;
    //perintah union
    cout<<"Union dari himpunan satu dan himpunan dua adalah:"<<endl;
    for (i=1;i<=jum1;i++){
    union1[i]=him1[i];
    cout<<union1[i]<<", ";
    }
    for (i=1;i<=jum2;i++){
    sama=false;
    for (j=1;j<=jum1;j++){
    if (him2[i]== him1[j]){
    sama=true;
    }

    }
    if (!sama){
    union1[i+jum1]=him2[i];
    cout<<union1[i+jum1]<<", ";
    }
    }
    break;
    case 0:ulang=='t';
    default:cout<<"bukan pilahan yang valid!";
    cout<<endl;
    cout<>ulang;
    }
    }while (ulang==’y’);
    }

  47. nama : nuryanto
    nim 09-11-3296

    #include
    #include
    #include
    #include

    void prog();
    int main()
    {
    prog();
    return 0;
    }

    void prog()
    {
    int jmlx, jmly, i, a[10], b[10];
    char choice[2];

    printf(“Input Jumlah Unsur Himpunan X (Maksimal 10): “);
    scanf(“%d”,&jmlx);

    for (i=1;i<=jmlx;i++)
    {
    printf("Input Unsur ke-%d = ", i);
    scanf("%d", &a[i]);
    }
    printf("—————————————————-\n");
    printf("Input Jumlah Unsur Himpunan Y (Maksimal 10): ");
    scanf("%d",&jmly);

    for (i=1;i<=jmly;i++)
    {
    printf("Input Unsur ke-%d = ", i);
    scanf("%d", &b[i]);
    }

    printf("—————————————————-\n");
    printf("—————————————————-\n");

    printf("X Irisan Y = ");
    for(i=1;i<=jmly;i++)
    {
    if (a[1]==b[i])
    printf(" %d,",a[1]);
    else
    cout<<"";

    if (a[2]==b[i])
    printf(" %d,",a[2]);
    else
    cout<<"";

    if (a[3]==b[i])
    printf(" %d,",a[3]);
    else
    cout<<"";

    if (a[4]==b[i])
    printf(" %d,",a[4]);
    else
    cout<<"";

    if (a[5]==b[i])
    printf(" %d,",a[5]);
    else
    cout<<"";

    if (a[6]==b[i])
    printf(" %d,",a[6]);
    else
    cout<<"";

    if (a[7]==b[i])
    printf(" %d,",a[7]);
    else
    cout<<"";

    if (a[8]==b[i])
    printf(" %d,",a[8]);
    else
    cout<<"";

    if (a[9]==b[i])
    printf(" %d,",a[9]);
    else
    cout<<"";

    if (a[10]==b[i])
    printf(" %d,",a[10]);
    else
    cout<<"";
    }
    printf("\nX Gabungan Y = ");
    for(i=1;i<jmlx;i++)
    {
    printf(" %d,", a[i]);
    }
    for(i=1;i<jmly;i++)
    {
    if (b[i]!= a[i])
    printf(" %d,", b[i]);
    else
    printf("");
    }
    printf("\n—————————————————-\n");
    printf("—————————————————-\n");

    cout<<endl<<"Mau coba lagi ga? (1 = ya, 2 = tidak)?: \n";
    cin.getline(choice,3);
    if(choice[0] == '1')
    prog();
    else
    exit(0);
    getch();

    Pake pengulangan ama array :

    Irisan :
    pake pengulangan gan
    Jika A = B maka ditandai dan dimasukkan ke array bantu.
    Di loop terus2an gan. Nah, terus entar dipanggil lagi ama pengulangan…

    Kalau gabungan, maka semua anggota A dan B pastinya dimasukkan ke variabel array bantu. Nah, kecuali yang nilainya sama (alias irisan) maka hanya dimasukkan satu aja

  48. /*
    Septian Ardianta
    09.11.3290
    SI TI 3J
    HIMPUNAN
    */

    #include
    #include

    int him1[50];
    int him2[50];
    int i,j,jum1,jum2,l;
    int irisan[50], union1[50];
    bool sama;

    void main(){
    cout<<" Masukkan data himpunan pertama"<<endl;
    cout<>jum1;
    for (i=1;i<=jum1;i++){
    cout<<"Data "<<i<>him1[i];
    }
    cout<<"himpunan pertama adalah ";
    cout<<"{";
    for(i=1;i<=jum1;i++){
    cout<<him1[i]<<", ";
    }
    cout<<"}";

    cout<<"\n Masukkan data himpunan kedua"<<endl;
    cout<>jum2;
    for (j=1;j<=jum2;j++){
    cout<<"Data "<<j<>him2[j];
    }
    cout<<"himpunan kedua adalah ";
    cout<<"{";
    for (j=1;j<=jum2;j++){
    cout<<him2[j]<<", ";
    }cout<<"}";

    //perintah irisan
    cout<<"\n Irisan dari kedua himpunan tersebut adalah ";
    cout<<"{";
    l=0;
    for (i=1;i<=jum1;i++){
    for (j=1;j<=jum2;j++){
    if (him1[i]==him2[j]){
    l=l+1;
    irisan[l]=him2[j];
    cout<<irisan[l]<<", ";
    }
    }
    } cout<<"}";

    cout<<"\n\n Gabungan dari kedua himpunan tersebut adalah ";
    // perintah gabungan
    cout<<"{";
    for (i=1;i<=jum1;i++){
    union1[i]=him1[i];
    cout<<union1[i]<<", ";
    }
    for (i=1;i<=jum2;i++){
    sama=false;
    for (j=1;j<=jum1;j++){
    if (him2[i]== him1[j]){
    sama=true;
    }
    }
    if (!sama){
    union1[i+jum1]=him2[i];
    cout<<union1[i+jum1]<<", ";
    }
    } cout<<"} ";

    getch(); }

    /*
    Hasilnya

    Masukkan data himpunan pertama
    Masukkan jumlah data = 3
    Data 1=2
    Data 2=3
    Data 3=1
    himpunan pertama adalah {2,3,1,}
    Masukkan data himpunan kedua
    Masukkan jumlah data = 3
    Data 1=4
    Data 2=5
    Data 3=1
    himpunan kedua adalah {4,5,1,}
    Irisan dari kedua himpunan tersebut adalah {1,}
    Gabungan dari kedua himpunan tersebut adalah {2,3,1,4,5,}
    */

  49. import java.io.*;
    class HimpunanTugas
    {
    public static void main (String [] args) throws Exception
    {
    BufferedReader input = new BufferedReader (new InputStreamReader (System.in));

    System.out.print (“banyaknya himpunan 1 yang dibutuhkan: “);
    int p = Integer.parseInt (input.readLine());
    int himpA [] = new int [p];
    for (int i=0; i<p; i++)
    {
    System.out.print ("element himpunan 1 yang ke- : " +(i+1)+":");
    String a=input.readLine ();
    himpA [i] = Integer.parseInt (a);
    }
    System.out.print ("A={");
    for (int i=0;i<p;i++)
    {
    System.out.print (himpA [i]);
    if (i!=p-1)
    System.out.print (",");
    }
    System.out.println ("}");

    System.out.print ("himpunan 2 yang dibutuhkan: ");
    int q=Integer.parseInt (input.readLine());
    int himpB [] = new int [q];
    for (int i=0;i<q;i++)
    {
    System.out.print ("elemen himpunan 2 yang ke-: "+(i+1)+":");
    String a=input.readLine ();
    himpB[i]=Integer.parseInt(a);
    }
    System.out.print("B={");
    for (int i=0;i<q;i++)
    {
    System.out.print (himpB[i]);
    if(i!=q-1)
    System.out.print (",");
    }
    System.out.println ("}");

    int ir;
    ir = 0;
    int himpC []=new int [p];
    for (int i=0;i<p;i++)
    for (int j=0;j<q;j++)
    {
    if (himpA [i]==himpB[j])
    {
    himpC[ir]=himpA[i];
    ir=ir+1;
    }
    }

    System.out.print("Irisannya ialah={");
    for (int i=0;i<ir;i++)
    {
    System.out.print(himpC[i]);
    if (i!=ir-1)
    System.out.print(",");
    }
    System.out.println("}");

    System.out.print ("dan Gabungannya ialah = {");

    for (int i=0; i<p; i++)
    {
    System.out.print ("("+himpA[i]+")");
    }
    boolean b = false;

    for (int j = 0;j<q;j++)
    {
    for (int i=0; i<p; i++)
    {
    if (himpB[j]==himpA[i])
    {
    b = true;
    break;
    }
    }

    if (b==false)
    {
    System.out.print ("("+himpB[j]+")");
    }
    b = false;
    }
    System.out.println ("}");
    System.out.println ();
    }
    }

    //tugas Desnanda Dewahyani
    //Nim 09.11.3305

  50. //Nama : Awaludin Abid
    //Nim : 09.11.3246
    import java.io.*;
    class Himpunan
    {
    public static void main (String [] args) throws Exception
    {
    BufferedReader input = new BufferedReader (new InputStreamReader (System.in));//BufferedReader untuk mendapatkan input dari keyboard

    System.out.print (“Masukan himpunan X yang dibutuhkan: “);
    int p = Integer.parseInt (input.readLine());//menetukan jumlah inputan himpunan
    int himpX [] = new int [p];
    for (int i=0; i<p; i++)
    {
    System.out.print ("Masukan element X yang ke- : " +(i+1)+":");//elemen dari himpunan
    String a=input.readLine ();
    himpX [i] = Integer.parseInt (a);
    }
    System.out.print ("X={");//menampilkan inputan
    for (int i=0;i<p;i++)
    {
    System.out.print (himpX [i]);
    if (i!=p-1)
    System.out.print (".");
    }
    System.out.println ("}");

    System.out.print ("Masukan himpunan Y yang dibutuhkan: ");
    int q=Integer.parseInt (input.readLine());//menetukan jumlah inputan himpunan
    int himpY [] = new int [q];
    for (int i=0;i<q;i++)
    {
    System.out.print ("Masukan elemen Y yang ke-: "+(i+1)+":");//elemen dari himpunan
    String a=input.readLine ();
    himpY[i]=Integer.parseInt(a);
    }
    System.out.print("Y={");//menampilkan inputan
    for (int i=0;i<q;i++)
    {
    System.out.print (himpY[i]);
    if(i!=q-1)
    System.out.print (".");
    }
    System.out.println ("}");

    int irisan;
    irisan = 0;
    int himpZ []=new int [p];
    for (int i=0;i<p;i++)
    for (int j=0;j<q;j++)
    {
    if (himpX [i]==himpY[j])//jika inputan himpunan X dan Y sama akan dimunculkan
    {
    himpZ[irisan]=himpX[i];
    irisan=irisan+1;
    }
    }

    System.out.print("\nHasil Irisannya={");
    for (int i=0;i<irisan;i++)
    {
    System.out.print(himpZ[i]);
    if (i!=irisan-1)
    System.out.print(".");
    }
    System.out.println("}");

    System.out.print ("Hasil Gabungannya= {");//gabungan memunculkan 1 kali inputan yang sama dr himpunan X dan Y dan memunculkan inputan yang tidak sama pad masing2 elemen

    for (int i=0; i<p; i++)
    {
    System.out.print ("("+himpX[i]+")");
    }
    boolean b = false;

    for (int j = 0;j<q;j++)
    {
    for (int i=0; i<p; i++)
    {
    if (himpY[j]==himpX[i])
    {
    b = true;
    break;
    }
    }

    if (b==false)
    {
    System.out.print ("("+himpY[j]+")");
    }
    b = false;
    }
    System.out.println ("}");
    System.out.println ();
    }
    }

  51. //Nama : Hario Persada Putra
    //Nim : 09.11.3238

    import java.io.*;
    class IrisanHimpunan
    {
    public static void main (String [] args) throws Exception
    {
    BufferedReader input = new BufferedReader (new InputStreamReader (System.in));
    System.out.print (“Tugas Matematika Diskret oleh Hario Persada Putra (3238)\n”);

    System.out.print (“Silahkan Anda masukan banyaknya himpunan A yang dibutuhkan: “);
    int p = Integer.parseInt (input.readLine());
    int himpA [] = new int [p];
    for (int i=0; i<p; i++)
    {
    System.out.print ("Silahkan Anda masukan element A yang ke- : " +(i+1)+":");
    String a=input.readLine ();
    himpA [i] = Integer.parseInt (a);
    }
    System.out.print ("A={");
    for (int i=0;i<p;i++)
    {
    System.out.print (himpA [i]);
    if (i!=p-1)
    System.out.print (".");
    }
    System.out.println ("}");

    System.out.print ("Silahkan Anda masukan banyaknya himpunan B yang dibutuhkan: ");
    int q=Integer.parseInt (input.readLine());
    int himpB [] = new int [q];
    for (int i=0;i<q;i++)
    {
    System.out.print ("Silahkan Anda masukan elemen B yang ke-: "+(i+1)+":");
    String a=input.readLine ();
    himpB[i]=Integer.parseInt(a);
    }
    System.out.print("B={");
    for (int i=0;i<q;i++)
    {
    System.out.print (himpB[i]);
    if(i!=q-1)
    System.out.print (".");
    }
    System.out.println ("}");

    int irisan;
    irisan = 0;
    int himpC []=new int [p];
    for (int i=0;i<p;i++)
    for (int j=0;j<q;j++)
    {
    if (himpA [i]==himpB[j])
    {
    himpC[irisan]=himpA[i];
    irisan=irisan+1;
    }
    }

    System.out.print("\nHasil Irisannya ialah={");
    for (int i=0;i<irisan;i++)
    {
    System.out.print(himpC[i]);
    if (i!=irisan-1)
    System.out.print(".");
    }
    System.out.println("}");

    System.out.print ("dan Gabungannya ialah = {");

    for (int i=0; i<p; i++)
    {
    System.out.print ("("+himpA[i]+")");
    }
    boolean b = false;

    for (int j = 0;j<q;j++)
    {
    for (int i=0; i<p; i++)
    {
    if (himpB[j]==himpA[i])
    {
    b = true;
    break;
    }
    }

    if (b==false)
    {
    System.out.print ("("+himpB[j]+")");
    }
    b = false;
    }
    System.out.println ("}");
    System.out.println ();
    }
    }

  52. import java.io.*;
    class Himpunan
    {
    public static void main (String [] args) throws Exception
    {
    BufferedReader input = new BufferedReader (new InputStreamReader (System.in));
    System.out.print (“Jumlah Himpunan 1: “);
    int x = Integer.parseInt (input.readLine());
    int himpA [] = new int [x];
    for (int i=0; i<x; i++){
    System.out.print ("Himpunan bagian 1 : " +(i+1)+":");
    String a=input.readLine ();
    himpA [i] = Integer.parseInt (a);
    }
    System.out.print ("A={");
    for (int i=0;i<x;i++){
    System.out.print (himpA [i]);
    if (i!=x-1)
    System.out.print (",");
    }
    System.out.println ("}");

    System.out.print ("Jumlah Himpunan 2: ");
    int y=Integer.parseInt (input.readLine());
    int himpB [] = new int [y];
    for (int i=0;i<y;i++){
    System.out.print ("Himpunan bagian 2: "+(i+1)+":");
    String a=input.readLine ();
    himpB[i]=Integer.parseInt(a);
    }
    System.out.print("B={");
    for (int i=0;i<y;i++){
    System.out.print (himpB[i]);
    if(i!=y-1)
    System.out.print (",");
    }
    System.out.println ("}");

    int irisan;
    irisan = 0;
    int himpC []=new int [x];
    for (int i=0;i<x;i++)
    for (int j=0;j<y;j++){
    if (himpA [i]==himpB[j])
    {
    himpC[irisan]=himpA[i];
    irisan=irisan+1;
    }
    }

    System.out.print("\n Himpunan Irisan ={");
    for (int i=0;i<irisan;i++)
    {
    System.out.print(himpC[i]);
    if (i!=irisan-1)
    System.out.print(",");
    }
    System.out.println("}");

    System.out.print ("Himpunan Gabungan = {");

    for (int i=0; i<x; i++)
    {
    System.out.print ("("+himpA[i]+")");}
    boolean b = false;
    for (int j = 0;j<y;j++)
    {
    for (int i=0; i<x; i++){
    if (himpB[j]==himpA[i]){
    b = true;
    break;
    }
    }

    if (b==false){
    System.out.print ("("+himpB[j]+")");
    }
    b = false;
    }
    System.out.println ("}");
    System.out.println ();
    }
    }

  53. //Nama : Danang Teguh Sri Hatmoko
    //Kelas : S1 TI 3J
    //NIM : 09.11.3289
    #include
    #include
    #include
    int him1[100];
    int him2[100];
    int i,j,jum1,jum2,l;
    int irisan[100];
    bool sama;
    void main(){
    cout<<"Menghutung Irisan Dua Buah Himpunan"<<endl;
    cout<<"==================================="<<endl;
    cout<>jum1;
    for (i=1;i<=jum1;i++){
    cout<<"Anggota "<<i<>him1[i];
    }
    cout<<"Himpunan pertama = { ";
    for (i=1;i<=jum1;i++){
    cout<<him1[i]<<" ";
    }
    cout<<"}"<<endl;
    cout<>jum2;
    for (j=1;j<=jum2;j++){
    cout<<"Anggota "<<j<>him2[j];
    }
    cout<<"Himpunan kedua = { ";
    for (j=1;j<=jum2;j++){
    cout<<him2[j]<<" ";
    }
    cout<<"}"<<endl;

    cout<<"Irisan dari kedua himpunan tersebut = { ";
    l=0;
    for (i=1;i<=jum1;i++)
    {
    for (j=1;j<=jum2;j++)
    {
    if (him1[i]==him2[j])
    {
    l=l+1;
    irisan[l]=him1[i];
    cout<<irisan[l]<<" ";
    }
    }
    }
    cout<<"}";
    getch();
    }

  54. package sarijavaapplication;

    import java.io.*;
    class MatematikaDiskret
    {
    public static void main (String [] args) throws Exception
    {
    BufferedReader input = new BufferedReader (new InputStreamReader (System.in));
    System.out.print (“Matematika Diskret_Suskomalasari (09.11.3300)\n”);

    System.out.print (“Masukkan banyaknya himpunan A yang diinginkan: “);
    int p = Integer.parseInt (input.readLine());
    int himpA [] = new int [p];
    for (int i=0; i<p; i++)
    {
    System.out.print ("Masukkan element A yang ke- " +(i+1)+":");
    String a=input.readLine ();
    himpA [i] = Integer.parseInt (a);
    }
    System.out.print ("A={");
    for (int i=0;i<p;i++)
    {
    System.out.print (himpA [i]);
    if (i!=p-1)
    System.out.print (".");
    }
    System.out.println ("}");

    System.out.print ("Masukkan banyaknya himpunan B yang diinginkan: ");
    int q=Integer.parseInt (input.readLine());
    int himpB [] = new int [q];
    for (int i=0;i<q;i++)
    {
    System.out.print ("Masukkan elemen B yang ke- "+(i+1)+":");
    String a=input.readLine ();
    himpB[i]=Integer.parseInt(a);
    }
    System.out.print("B={");
    for (int i=0;i<q;i++)
    {
    System.out.print (himpB[i]);
    if(i!=q-1)
    System.out.print (".");
    }
    System.out.println ("}");

    int irisan;
    irisan = 0;
    int himpC []=new int [p];
    for (int i=0;i<p;i++)
    for (int j=0;j<q;j++)
    {
    if (himpA [i]==himpB[j])
    {
    himpC[irisan]=himpA[i];
    irisan=irisan+1;
    }
    }

    System.out.print("\nHasil Irisannya ialah={");
    for (int i=0;i<irisan;i++)
    {
    System.out.print(himpC[i]);
    if (i!=irisan-1)
    System.out.print(".");
    }
    System.out.println("}");

    System.out.print ("dan Gabungannya ialah = {");

    for (int i=0; i<p; i++)
    {
    System.out.print ("("+himpA[i]+")");
    }
    boolean b = false;

    for (int j = 0;j<q;j++)
    {
    for (int i=0; i<p; i++)
    {
    if (himpB[j]==himpA[i])
    {
    b = true;
    break;
    }
    }

    if (b==false)
    {
    System.out.print ("("+himpB[j]+")");
    }
    b = false;
    }
    System.out.println ("}");
    System.out.println ();
    }
    }

  55. import java.io.*;
    class TugasHimpunan
    {
    public static void main (String [] args) throws Exception
    {
    BufferedReader input = new BufferedReader (new InputStreamReader (System.in));
    System.out.print (“Discrete Mathematics Assignment by Normalita Amilia (09.11.3252)\n”);

    System.out.print (“Please input the required number of set A: “);
    int k = Integer.parseInt (input.readLine());
    int himpA [] = new int [k];
    for (int i=0; i<k; i++){
    System.out.print ("Please input element A : " +(i+1)+":");
    String a=input.readLine ();
    himpA [i] = Integer.parseInt (a);
    }
    System.out.print ("A={");
    for (int i=0;i<k;i++){
    System.out.print (himpA [i]);
    if (i!=k-1)
    System.out.print (",");
    }
    System.out.println ("}");

    System.out.print ("Please input the required number of set B: ");
    int l=Integer.parseInt (input.readLine());
    int himpB [] = new int [l];
    for (int i=0;i<l;i++){
    System.out.print ("Please input element B: "+(i+1)+":");
    String a=input.readLine ();
    himpB[i]=Integer.parseInt(a);
    }
    System.out.print("B={");
    for (int i=0;i<l;i++){
    System.out.print (himpB[i]);
    if(i!=l-1)
    System.out.print (",");
    }
    System.out.println ("}");

    int irisan;
    irisan = 0;
    int himpC []=new int [k];
    for (int i=0;i<k;i++)
    for (int j=0;j<l;j++){
    if (himpA [i]==himpB[j])
    {
    himpC[irisan]=himpA[i];
    irisan=irisan+1;
    }
    }

    System.out.print("\n The result is ={");
    for (int i=0;i<irisan;i++)
    {
    System.out.print(himpC[i]);
    if (i!=irisan-1)
    System.out.print(",");
    }
    System.out.println("}");

    System.out.print ("And The result of Union is = {");

    for (int i=0; i<k; i++)
    {
    System.out.print ("("+himpA[i]+")");}
    boolean b = false;
    for (int j = 0;j<l;j++)
    {
    for (int i=0; i<k; i++){
    if (himpB[j]==himpA[i]){
    b = true;
    break;
    }
    }

    if (b==false){
    System.out.print ("("+himpB[j]+")");
    }
    b = false;
    }
    System.out.println ("}");
    System.out.println ();
    }
    }

  56. package himpunan;

    import javax.swing.JOptionPane;

    /**
    *
    * @author P.N.W 09.11.3304
    * Name : Pratama Nur Wijaya
    * NIM : 09.11.3304
    * Class : S1 TI 3J
    */
    public class Sets {

    //method / function gabungan
    public int []gabung(int []a,int []b) {

    int []temp = new int[a.length + b.length];
    int n = 0;

    // copy semua nilai a ke temp
    for(int i=0;i<a.length;i++)
    temp[n++] = a[i];

    // copy semua nilai b yang tidak ada di a
    for(int i=0;i<b.length;i++) {
    boolean ada = false;
    for(int j=0;j<a.length && !ada;j++)
    if(a[j]==b[i]) ada = true;

    // jika tidak ada baru kita copy
    if(!ada) temp[n++] = b[i];
    }

    // copy nilai temp ke ret
    int []ret = new int[n];
    System.arraycopy(temp, 0, ret, 0, n);

    return ret;
    }

    //method/function gabungan
    public int []irisan(int []a,int []b) {
    int []temp = new int[b.length];
    int n = 0;

    // copy semua nilai b yang ada di a
    for(int i=0;i<b.length;i++) {
    boolean ada = false;
    for(int j=0;j<a.length && !ada;j++)
    if(a[j]==b[i]) ada = true;

    // jika ada baru kita copy
    if(ada) temp[n++] = b[i];
    }

    // copy nilai temp ke ret
    int []ret = new int[n];
    System.arraycopy(temp, 0, ret, 0, n);

    return ret;
    }

    public static void main(String[] args) {

    try {
    //buat objek baru dari class Sets
    Sets sets = new Sets();
    //variable untuk menentukan banyaknya Himpunan A dan B
    int n, m;
    //minta masukan
    n = Integer.parseInt(JOptionPane.showInputDialog("Masukkan

    banyaknya "
    + "anggota Himpunan A"));
    //buat sebuah array
    int [] a;
    a = new int[n];
    //lopping inputan sebanyak n yang dimasukkan user
    for (int i = 0; i < n; i++) {
    a[i] = Integer.parseInt(JOptionPane.showInputDialog("Masukkan"
    + " anggota ke -" + (i+1)));
    }
    //minta berapa banyaknya himpunan B
    m = Integer.parseInt(JOptionPane.showInputDialog("Masukkan

    banyaknya "
    + "anggota Himpunan B"));
    //buat array B
    int [] b;
    b = new int[m];
    //looping lagi untuk Himpunan B
    for (int i = 0; i < m; i++) {
    b[i] = Integer.parseInt(JOptionPane.showInputDialog("Masukkan"
    + " anggota ke -" + (i+1)));
    }
    //tampilkan anggota Himpunan A
    System.out.println("Anggota Himpunan A");
    for (int i = 0; i < n; i++) {
    System.out.print(a[i] + ",");
    }
    System.out.println("");

    System.out.println("Anggota Himpunan B");
    for (int i = 0; i < m; i++) {
    System.out.print(b[i] + ",");
    }
    System.out.println("");

    int g[] = sets.gabung(a, b);
    int x[] = sets.irisan(a, b);

    System.out.println("Hasil Gabungan :");
    for (int i = 0; i < g.length; i++) {
    System.out.print(g[i] + ",");

    }
    System.out.println("");

    System.out.println("Hasil Irisan :");
    for (int i = 0; i < x.length; i++) {
    System.out.print(x[i] + ",");
    }
    System.out.println("");

    } catch (Exception e) {
    JOptionPane.showMessageDialog(null, "Error");
    }

    }

    }

    note: untuk picture jalannya program,, dapat dilihat disini http://pratomo-wijoyo.blogspot.com/2010/11/mencari-irisan-gabungan-java.html

  57. NAMA : REBLI WIDIYANTO
    NIM : 09.11.3240

    #include
    #include
    int him1[100];
    int him2[100];
    int i,j,jum1,jum2,l;
    int irisan[100], union1[100];
    bool sama;

    menu();
    Union_Intersection();
    complement();
    difference();

    menu(){
    char pilih;

    cout << "\nA = Union dan Intersection \n";
    cout << "B = Complement \n";
    cout << "C = Difference \n";
    cout <> pilih;
    switch(pilih){
    case ‘A’:
    Union_Intersection();

    case ‘B’:
    complement();

    case ‘C’:
    difference();

    default:
    cout << "\n Silahkan masukan pilihan yang valid \n";
    menu();
    }
    return pilih;
    }

    // Union_Iintersection()
    Union_Intersection(){
    clrscr();
    cout<<" Masukkan data himpunan pertama "<<endl;
    cout<>jum1;
    for (i=1;i<=jum1;i++){
    cout<<" Data "<<i<>him1[i];
    }
    cout<<" Himpunan pertama : ";
    for(i=1;i<=jum1;i++){
    cout<<him1[i]<<" ";
    }
    cout<<endl;

    cout<<"\n Masukkan data himpunan kedua "<<endl;
    cout<>jum2;
    for (j=1;j<=jum2;j++){
    cout<<" Data "<<j<>him2[j];
    }
    cout<<" Himpunan kedua : ";
    for (j=1;j<=jum2;j++){
    cout<<him2[j]<<" ";
    } cout<<endl;

    //perintah Intersection
    cout<<"\n Iintersection dari kedua himpunan tersebut adalah: ";
    l=0;
    for (i=1;i<=jum1;i++){
    for (j=1;j<=jum2;j++){
    if (him1[i]==him2[j]){
    l=l+1;
    irisan[l]=him2[j];
    cout<<irisan[l]<<" ";
    }
    }
    }

    cout<<"\n\n Union dari kedua himpunan adalah : ";
    // perintah Union
    for (i=1;i<=jum1;i++){
    union1[i]=him1[i];
    cout<<union1[i]<<", ";
    }
    for (i=1;i<=jum2;i++){
    sama=false;
    for (j=1;j<=jum1;j++){
    if (him2[i]== him1[j]){
    sama=true;
    }
    }
    if (!sama){
    union1[i+jum1]=him2[i];
    cout<<union1[i+jum1]<<", ";
    }
    } while(getch()=='y');
    clrscr();
    menu();
    return 0;
    }

    // complement()
    complement(){
    clrscr();
    cout<<" Masukkan himpunan universal "<<endl;
    cout<>jum1;
    for (i=1;i<=jum1;i++){
    cout<<" Data "<<i<>him1[i];
    }
    cout<<" Himpunan Universal : ";
    for(i=1;i<=jum1;i++){
    cout<<him1[i]<<" ";
    }
    cout<<endl;

    cout<<"\n Masukkan data himpunan A "<<endl;
    cout<>jum2;
    for (j=1;j<=jum2;j++){
    cout<<" Data "<<j<>him2[j];
    }
    cout<<" Himpunan A : ";
    for (j=1;j<=jum2;j++){
    cout<<him2[j]<<" ";
    } cout<<endl;

    //perintah complement
    cout<<"\n Complement dari himpunan A adalah: ";

    for (i=1;i<=jum1;i++){
    l=0;
    for (j=1;j<=jum2;j++){
    if (him1[i]==him2[j])
    l=1;
    }
    if(l==0){
    cout<< him1[i] << " " ;
    }
    }while(getch()=='y');
    clrscr();
    menu();
    return 0;
    }

    //difference()
    difference(){
    cout<<" Masukkan himpunan A "<<endl;
    cout<>jum1;
    for (i=1;i<=jum1;i++){
    cout<<" Data "<<i<>him1[i];
    }
    cout<<" Himpunan A : ";
    for(i=1;i<=jum1;i++){
    cout<<him1[i]<<" ";
    }
    cout<<endl;

    cout<<"\n Masukkan data himpunan B "<<endl;
    cout<>jum2;
    for (j=1;j<=jum2;j++){
    cout<<" Data "<<j<>him2[j];
    }
    cout<<" Himpunan B : ";
    for (j=1;j<=jum2;j++){
    cout<<him2[j]<<" ";
    } cout<<endl;

    //perintah difference()
    cout<<"\n Difference dari himpunan A – B adalah: ";

    for (i=1;i<=jum1;i++){
    l=0;
    for (j=1;j<=jum2;j++){
    if (him1[i]==him2[j])
    l=1;
    }
    if(l==0){
    cout<< him1[i] << " " ;
    }
    }while(getch()=='y');
    clrscr();
    menu();
    return 0;
    }

    void main(){
    menu();
    getch();
    }

    Hasilnya :

    Masukkan data himpunan pertama
    Masukkan jumlah data : 4
    Data 1 : 1
    Data 2 : 2
    Data 3 : 3
    Data 4 : 4
    Himpunan pertama : 1 2 3 4

    Masukkan data himpunan kedua

    Masukkan jumlah data:5
    Data 1 : 3
    Data 2 : 4
    Data 3 : 5
    Data 4 : 6
    Data 5 : 7
    Himpunan kedua : 3 4 5 6 7

    Iintersection dari kedua himpunan tersebut adalah: 3 4

    Union dari kedua himpunan adalah : 1, 2, 3, 4, 5, 6, 7,

    Masukkan himpunan universal
    Masukkan jumlah data:4
    Data 1 : 1
    Data 2 : 2
    Data 3 : 3
    Data 4 : 4
    Himpunan Universal : 1 2 3 4

    Masukkan data himpunan A
    Masukkan jumlah data:5
    Data 1 : 3
    Data 2 : 4
    Data 3 : 5
    Data 4 : 6
    Data 5 : 7
    Himpunan A : 3 4 5 6 7

    Complement dari himpunan A adalah: 1 2

    Masukkan jumlah data:4
    Data 1 : 12
    Data 2 : 2
    Data 3 : 3
    Data 4 : 4
    Himpunan A : 12 2 3 4

    Masukkan data himpunan B
    Masukkan jumlah data:5
    Data 1 : 3
    Data 2 : 4
    Data 3 : 5
    Data 4 : 1
    Data 5 : 5
    Himpunan B : 3 4 5 1 5

    Difference dari himpunan A – B adalah: 12 2

  58. NAMA : REBLI WIDIYANTO
    NIM :09.11.3240

    #include
    #include
    int him1[100];
    int him2[100];
    int i,j,jum1,jum2,l;
    int irisan[100], union1[100];
    bool sama;

    menu();
    Union_Intersection();
    complement();
    difference();

    menu(){
    char pilih;

    cout << "\nA = Union dan Intersection \n";
    cout << "B = Complement \n";
    cout << "C = Difference \n";
    cout <> pilih;
    switch(pilih){
    case ‘A’:
    Union_Intersection();

    case ‘B’:
    complement();

    case ‘C’:
    difference();

    default:
    cout << "\n Silahkan masukan pilihan yang valid \n";
    menu();
    }
    return pilih;
    }

    // Union_Iintersection()
    Union_Intersection(){
    clrscr();
    cout<<" Masukkan data himpunan pertama "<<endl;
    cout<>jum1;
    for (i=1;i<=jum1;i++){
    cout<<" Data "<<i<>him1[i];
    }
    cout<<" Himpunan pertama : ";
    for(i=1;i<=jum1;i++){
    cout<<him1[i]<<" ";
    }
    cout<<endl;

    cout<<"\n Masukkan data himpunan kedua "<<endl;
    cout<>jum2;
    for (j=1;j<=jum2;j++){
    cout<<" Data "<<j<>him2[j];
    }
    cout<<" Himpunan kedua : ";
    for (j=1;j<=jum2;j++){
    cout<<him2[j]<<" ";
    } cout<<endl;

    //perintah Intersection
    cout<<"\n Iintersection dari kedua himpunan tersebut adalah: ";
    l=0;
    for (i=1;i<=jum1;i++){
    for (j=1;j<=jum2;j++){
    if (him1[i]==him2[j]){
    l=l+1;
    irisan[l]=him2[j];
    cout<<irisan[l]<<" ";
    }
    }
    }

    cout<<"\n\n Union dari kedua himpunan adalah : ";
    // perintah Union
    for (i=1;i<=jum1;i++){
    union1[i]=him1[i];
    cout<<union1[i]<<", ";
    }
    for (i=1;i<=jum2;i++){
    sama=false;
    for (j=1;j<=jum1;j++){
    if (him2[i]== him1[j]){
    sama=true;
    }
    }
    if (!sama){
    union1[i+jum1]=him2[i];
    cout<<union1[i+jum1]<<", ";
    }
    } while(getch()=='y');
    clrscr();
    menu();
    return 0;
    }

    // complement()
    complement(){
    clrscr();
    cout<<" Masukkan himpunan universal "<<endl;
    cout<>jum1;
    for (i=1;i<=jum1;i++){
    cout<<" Data "<<i<>him1[i];
    }
    cout<<" Himpunan Universal : ";
    for(i=1;i<=jum1;i++){
    cout<<him1[i]<<" ";
    }
    cout<<endl;

    cout<<"\n Masukkan data himpunan A "<<endl;
    cout<>jum2;
    for (j=1;j<=jum2;j++){
    cout<<" Data "<<j<>him2[j];
    }
    cout<<" Himpunan A : ";
    for (j=1;j<=jum2;j++){
    cout<<him2[j]<<" ";
    } cout<<endl;

    //perintah complement
    cout<<"\n Complement dari himpunan A adalah: ";

    for (i=1;i<=jum1;i++){
    l=0;
    for (j=1;j<=jum2;j++){
    if (him1[i]==him2[j])
    l=1;
    }
    if(l==0){
    cout<< him1[i] << " " ;
    }
    }while(getch()=='y');
    clrscr();
    menu();
    return 0;
    }

    //difference()
    difference(){
    cout<<" Masukkan himpunan A "<<endl;
    cout<>jum1;
    for (i=1;i<=jum1;i++){
    cout<<" Data "<<i<>him1[i];
    }
    cout<<" Himpunan A : ";
    for(i=1;i<=jum1;i++){
    cout<<him1[i]<<" ";
    }
    cout<<endl;

    cout<<"\n Masukkan data himpunan B "<<endl;
    cout<>jum2;
    for (j=1;j<=jum2;j++){
    cout<<" Data "<<j<>him2[j];
    }
    cout<<" Himpunan B : ";
    for (j=1;j<=jum2;j++){
    cout<<him2[j]<<" ";
    } cout<<endl;

    //perintah difference()
    cout<<"\n Difference dari himpunan A – B adalah: ";

    for (i=1;i<=jum1;i++){
    l=0;
    for (j=1;j<=jum2;j++){
    if (him1[i]==him2[j])
    l=1;
    }
    if(l==0){
    cout<< him1[i] << " " ;
    }
    }while(getch()=='y');
    clrscr();
    menu();
    return 0;
    }

    void main(){
    menu();
    getch();
    }

    HASILNYA :

    Masukkan data himpunan pertama
    Masukkan jumlah data : 3
    Data 1 : 1
    Data 2 : 2
    Data 3 : 3
    Himpunan pertama : 1 2 3

    Masukkan data himpunan kedua

    Masukkan jumlah data:5
    Data 1 : 3
    Data 2 : 4
    Data 3 : 5
    Data 4 : 6
    Data 5 : 1
    Himpunan kedua : 3 4 5 6 1

    Iintersection dari kedua himpunan tersebut adalah: 1 3

    Union dari kedua himpunan adalah : 1, 2, 3, 4, 5, 6,

    Masukkan himpunan universal
    Masukkan jumlah data:4
    Data 1 : 1
    Data 2 : 23
    Data 3 : 3
    Data 4 : 4
    Himpunan Universal : 1 2 3 4

    Masukkan data himpunan A
    Masukkan jumlah data:3
    Data 1 : 3
    Data 2 : 4
    Data 3 : 5
    Himpunan A : 3 4 5

    Complement dari himpunan A adalah: 1 2

    Masukkan jumlah data:4
    Data 1 : 3
    Data 2 : 4
    Data 3 : 1
    Data 4 : 2
    Himpunan A : 3 4 1 2

    Masukkan data himpunan B
    Masukkan jumlah data:5
    Data 1 : 2
    Data 2 : 5
    Data 3 : 6
    Data 4 : 3
    Data 5 : 7
    Himpunan B : 2 5 6 3 7

    Difference dari himpunan A – B adalah: 4 1

  59. #include
    #include
    int him1[100];
    int him2[100];
    int i,j,jum1,jum2,l;
    int irisan[100], union1[100];
    bool sama;

    menu();
    Union_Intersection();
    complement();
    difference();

    menu(){
    char pilih;

    cout << "\nA = Union dan Intersection \n";
    cout << "B = Complement \n";
    cout << "C = Difference \n";
    cout <> pilih;
    switch(pilih){
    case ‘A’:
    Union_Intersection();

    case ‘B’:
    complement();

    case ‘C’:
    difference();

    default:
    cout << "\n Silahkan masukan pilihan yang valid \n";
    menu();
    }
    return pilih;
    }

    // Union_Iintersection()
    Union_Intersection(){
    clrscr();
    cout<<" Masukkan data himpunan pertama "<<endl;
    cout<>jum1;
    for (i=1;i<=jum1;i++){
    cout<<" Data "<<i<>him1[i];
    }
    cout<<" Himpunan pertama : ";
    for(i=1;i<=jum1;i++){
    cout<<him1[i]<<" ";
    }
    cout<<endl;

    cout<<"\n Masukkan data himpunan kedua "<<endl;
    cout<>jum2;
    for (j=1;j<=jum2;j++){
    cout<<" Data "<<j<>him2[j];
    }
    cout<<" Himpunan kedua : ";
    for (j=1;j<=jum2;j++){
    cout<<him2[j]<<" ";
    } cout<<endl;

    //perintah Intersection
    cout<<"\n Iintersection dari kedua himpunan tersebut adalah: ";
    l=0;
    for (i=1;i<=jum1;i++){
    for (j=1;j<=jum2;j++){
    if (him1[i]==him2[j]){
    l=l+1;
    irisan[l]=him2[j];
    cout<<irisan[l]<<" ";
    }
    }
    }

    cout<<"\n\n Union dari kedua himpunan adalah : ";
    // perintah Union
    for (i=1;i<=jum1;i++){
    union1[i]=him1[i];
    cout<<union1[i]<<", ";
    }
    for (i=1;i<=jum2;i++){
    sama=false;
    for (j=1;j<=jum1;j++){
    if (him2[i]== him1[j]){
    sama=true;
    }
    }
    if (!sama){
    union1[i+jum1]=him2[i];
    cout<<union1[i+jum1]<<", ";
    }
    } while(getch()=='y');
    clrscr();
    menu();
    return 0;
    }

    // complement()
    complement(){
    clrscr();
    cout<<" Masukkan himpunan universal "<<endl;
    cout<>jum1;
    for (i=1;i<=jum1;i++){
    cout<<" Data "<<i<>him1[i];
    }
    cout<<" Himpunan Universal : ";
    for(i=1;i<=jum1;i++){
    cout<<him1[i]<<" ";
    }
    cout<<endl;

    cout<<"\n Masukkan data himpunan A "<<endl;
    cout<>jum2;
    for (j=1;j<=jum2;j++){
    cout<<" Data "<<j<>him2[j];
    }
    cout<<" Himpunan A : ";
    for (j=1;j<=jum2;j++){
    cout<<him2[j]<<" ";
    } cout<<endl;

    //perintah complement
    cout<<"\n Complement dari himpunan A adalah: ";

    for (i=1;i<=jum1;i++){
    l=0;
    for (j=1;j<=jum2;j++){
    if (him1[i]==him2[j])
    l=1;
    }
    if(l==0){
    cout<< him1[i] << " " ;
    }
    }while(getch()=='y');
    clrscr();
    menu();
    return 0;
    }

    //difference()
    difference(){
    cout<<" Masukkan himpunan A "<<endl;
    cout<>jum1;
    for (i=1;i<=jum1;i++){
    cout<<" Data "<<i<>him1[i];
    }
    cout<<" Himpunan A : ";
    for(i=1;i<=jum1;i++){
    cout<<him1[i]<<" ";
    }
    cout<<endl;

    cout<<"\n Masukkan data himpunan B "<<endl;
    cout<>jum2;
    for (j=1;j<=jum2;j++){
    cout<<" Data "<<j<>him2[j];
    }
    cout<<" Himpunan B : ";
    for (j=1;j<=jum2;j++){
    cout<<him2[j]<<" ";
    } cout<<endl;

    //perintah difference()
    cout<<"\n Difference dari himpunan A – B adalah: ";

    for (i=1;i<=jum1;i++){
    l=0;
    for (j=1;j<=jum2;j++){
    if (him1[i]==him2[j])
    l=1;
    }
    if(l==0){
    cout<< him1[i] << " " ;
    }
    }while(getch()=='y');
    clrscr();
    menu();
    return 0;
    }

    void main(){
    menu();
    getch();
    }

    • HASILNYA :

      Masukkan data himpunan pertama
      Masukkan jumlah data : 4
      Data 1 : 2
      Data 2 : 3
      Data 3 : 4
      Data 4 : 5
      Himpunan pertama : 2 3 4 5

      Masukkan data himpunan kedua

      Masukkan jumlah data:3
      Data 1 : 1
      Data 2 : 2
      Data 3 : 3
      Himpunan kedua : 1 2 3

      Iintersection dari kedua himpunan tersebut adalah: 2 3

      Union dari kedua himpunan adalah : 2, 3, 4, 5, 1,

      Masukkan himpunan universal
      Masukkan jumlah data:5
      Data 1 : 1
      Data 2 : 2
      Data 3 : 3
      Data 4 : 4
      Data 5 : 5
      Himpunan Universal : 1 2 3 4 5

      Masukkan data himpunan A
      Masukkan jumlah data:6
      Data 1 : 1
      Data 2 : 2
      Data 3 : 6
      Data 4 : 7
      Data 5 : 8
      Data 6 : 7
      Himpunan A : 1 2 6 7 8 7

      Complement dari himpunan A adalah: 3 4 5

      Masukkan himpunan A
      Masukkan jumlah data:4
      Data 1 : 1
      Data 2 : 2
      Data 3 : 3
      Data 4 : 4
      Himpunan A : 1 2 3 4

      Masukkan data himpunan B
      Masukkan jumlah data:5
      Data 1 : 4
      Data 2 : 5
      Data 3 : 6
      Data 4 : 7
      Data 5 : 8
      Himpunan B : 4 5 6 7 8

      Difference dari himpunan A – B adalah: 1 2 3

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s