Array Dengan Bahasa C

Posted on Updated on


Program Penghitungan Matriks dengan memanfaatkan array


/*Program Membuat Matriks*/
#include<stdio.h>
#include<conio.h>
main()
{
 int A[100] [100];
 int m,n,i,j;
 /*-------menentukan banyaknya baris & kolom martriks----*/
 clrscr();
 printf("Matriks berordo m x n \n");
 printf("----------------------\n\n");
 printf("masukan banyaknya baris (m) : ");
 scanf("%i,%i", &m);
 printf("masukan banyaknya kolom (n) : ");
 scanf("%i,%i", &n);
 printf("\n");
 /* ------input elemen matriks ------*/
 for(i=0;i<m;i++)
 {
 for(j=0;j<n;j++)
 {printf("Elemen matriks A[%i,%i] : ",i+1,j+1);
 scanf("%i",&A[i][j]);
 }
 }
 /*------menampilkan elemen matriks--------*/
 printf("\n");
 printf("Matriks A= \n\n");
 for(i=0;i<m;i++)
 {
 for(j=0;j<n;j++)
 {
 printf("%3i",A[i][j]);
 }
 printf("\n");
 }
getch();
}

Contoh lain,


/*Program Membuat Matriks*/
#include<stdio.h>
#include<conio.h>
main()
{
 int A[100] [100];
 int B[100] [100];
 int C[100] [100];
 int m,n,i,j;
 char pilihan;
 do
 {

/*-------menentukan banyaknya baris & kolom martriks----*/
 clrscr();
 printf("Matriks berordo m x n \n");
 printf("----------------------\n\n");
 printf("masukan banyaknya baris (m) : ");
 scanf("%i,%i", &m);
 printf("masukan banyaknya kolom (n) : ");
 scanf("%i,%i", &n);
 printf("\n");
 /* ------input elemen matriks A ------*/
 for(i=0;i<m;i++)
 {
 for(j=0;j<n;j++)
 {printf("Elemen matriks A[%i,%i] : ",i+1,j+1);
 scanf("%i",&A[i][j]);
 }
 }

/* ------input elemen matriks B------*/
 for(i=0;i<m;i++)
 {
 for(j=0;j<n;j++)
 {printf("Elemen matriks B[%i,%i] : ",i+1,j+1);
 scanf("%i",&B[i][j]);
 }
 }

&nbsp;

/*---menjumlahkan elemen matriks A dg B----*/
 for(i=0; i<m;i++)
 {
 for(j=0;j<n;j++)
 {
 C[i][j]=A[i][j]+B[i][j];
 }
 }
 /*------menampilkan elemen matriks A--------*/
 printf("\n");
 printf("Matriks A= \n\n");
 for(i=0;i<m;i++)
 {
 for(j=0;j<n;j++)
 {
 printf("%3i",A[i][j]);
 }
 printf("\n");
 }

/*------menampilkan elemen matriks B--------*/
 printf("\n");
 printf("Matriks B= \n\n");
 for(i=0;i<m;i++)
 {
 for(j=0;j<n;j++)
 {
 printf("%3i",B[i][j]);
 }
 printf("\n");
 }

/*------menampilkan elemen matriks c Hasil penjumlahan+--------*/
 printf("\n");
 printf("Matriks C= \n\n");
 for(i=0;i<m;i++)
 {
 for(j=0;j<n;j++)
 {
 printf("%3i",C[i][j]);
 }
 printf("\n");
 }
 printf("apakah anda ingin memasukkan lagi datanya:[y|t] ");scanf("%c",&pilihan);
}

while(pilihan=='Y' || pilihan=='y');
getch();
}

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