13 Februari 2012

Widgets

Contoh Program Matriks dengan C++

#include<stdio.h>
#include<conio.h>
void main()
{
printf("Inputan Matriks A :\n");
int matrik[2][2];
int matriks[2][2];
int baris,kolom;
for ( baris=0 ; baris<2 ; baris++){
for ( kolom=0 ; kolom<2 ; kolom++){
        printf("\tMasukan Matrik Elemen [%d,%d] = ",baris,kolom);
        scanf("%d",&matrik[baris][kolom]);
    }
 }

printf("\n \tMatriks A :\n",baris,kolom);
for ( baris=0 ; baris<2 ; baris++){
for ( kolom=0 ; kolom<2 ; kolom++){
        printf("\t%d",matrik[baris][kolom]);
    }
        printf("\n");
 }

printf("\n\tBilangan Ganjil Matrik A : \n",baris,kolom);
      for (baris=0;baris<2;baris++){
            for (kolom=0;kolom<2;kolom++) {
      if (matrik[baris][kolom]%2==1)
      printf("\t%d",matrik[baris][kolom]);

      }
      printf("\n"); }

printf("\n\tBilangan Genap Matrik A : \n",baris,kolom);
      for (baris=0;baris<2;baris++){
            for (kolom=0;kolom<2;kolom++) {
      if (matrik[baris][kolom]%2==0)
      printf("\t%d",matrik[baris][kolom]);
      }
      printf("\n"); }

printf("\n\tMatrik B Tekan Enter...>>>\n");
getch();

printf("\nInputan Matrik B :\n");
for ( baris=0 ; baris<2 ; baris++){
for ( kolom=0 ; kolom<2 ; kolom++){
        printf("\tMasukan Matrik Elemen [%d,%d] = ",baris,kolom);
        scanf("%d",&matriks[baris][kolom]);
    }
 }

printf("\n \tMatrik B :\n",baris,kolom);
for ( baris=0 ; baris<2 ; baris++){
for ( kolom=0 ; kolom<2 ; kolom++){
        printf("\t%d",matriks[baris][kolom]);
    }
        printf("\n");
 }

printf("\n\tBilangan Ganjil Matrik B : \n",baris,kolom);
      for (baris=0;baris<2;baris++){
            for (kolom=0;kolom<2;kolom++) {
      if (matrik[baris][kolom]%2==1)
      printf("\t%d",matrik[baris][kolom]);
      }
      printf("\n"); }

printf("\n\tBilangan Genap Matrik B : \n",baris,kolom);
      for (baris=0;baris<2;baris++){
            for (kolom=0;kolom<2;kolom++) {
      if (matrik[baris][kolom]%2==0)
      printf("\t%d",matrik[baris][kolom]);
      }
      printf("\n"); }

printf("\n\tPenjumlahan,Pengurangan Tekan Enter...>>>\n");
getch();

//*************PENJUMLAHAN**********************
printf("\n\tHasil Penjumlahan Matrik A + Matrik B\n");
for ( baris=0 ; baris<2 ; baris++){
for ( kolom=0 ; kolom<2 ; kolom++){
        printf("\t%d",matrik[baris][kolom]+matriks[baris][kolom]);
    }
        printf("\n");
 }

//***********PENGURANGAN****************
printf("\n\tHasil Pengurangan Matrik A - Matrik B \n");
for ( baris=0 ; baris<2 ; baris++){
for ( kolom=0 ; kolom<2 ; kolom++){
        printf("\t%d",matrik[baris][kolom]-matriks[baris][kolom]);
    }
        printf("\n");
 }

printf("\n\tTranspose Tekan Enter...>>>\n");
getch();

//*********TRANSPOSE****************
printf("\n\tTranspose Matrik A :\n",baris,kolom);
for ( baris=0 ; baris<2 ; baris++){
for ( kolom=0 ; kolom<2 ; kolom++){
        printf("\t%d",matrik[kolom][baris]);
    }
        printf("\n");
 }


printf("\n\tTarnspose Matrik B :\n",baris,kolom);
for ( baris=0 ; baris<2 ; baris++){
for ( kolom=0 ; kolom<2 ; kolom++){
        printf("\t%d",matriks[kolom][baris]);
     }
        printf("\n");
    }
}

SHARE THIS POST   

  • Facebook
  • Twitter
  • Myspace
  • Google Buzz
  • Reddit
  • Stumnleupon
  • Delicious
  • Digg
  • Technorati
Author: Mohammad
Mohammad is the founder of STC Network which offers Web Services and Online Business Solutions to clients around the globe. Read More →