Sunday, May 23, 2010

listing C++ penjumlahan dua matriks

//penjumnlahan dua matriks
#include
#include
#include

garis()
{printf("***********--{@}--***********\n");}
//fungsi ;mengurangi penulisan (listing jadi lebih pendek)

main()
{
int A[5][5],B[5][5],X[5][5],Y[5][5],C[5][5],i,j;
clrscr();
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{printf("input nilai -{A}- [%i] [%i] : ",i+1,j+1);scanf("%i",&A[i][j]);}
//silahkan input nilai buat matriks A
//karna jangkauannya cuma 4(4 baris & 4 kolom)maka anda bisa menginput 16X
}

printf("\n");
garis();
printf("\n");

for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{printf("input nilai -{B}- [%i] [%i] : ",i+1,j+1);scanf("%i",&B[i][j]);}
//silahkan input nilai buat matriks B
//sama dengan matriks A, matriks B juga 16X inputan
}

printf("\n");
garis();
printf("\n");

for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{X[i][j]=A[i][j]+B[i][j];}
}
//klik enter untuk menampilkan hasil
clrscr();
//setalah layar inputan dibersihkan
//maka akan di tampilkan layar baru yang menampilkan A&B serta hasil penjumlahannya
printf("\n");
printf("\t {matrik.A}\n");
printf("\n");

garis();
//tampilan matriks A

printf("\n");
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
printf("%6i",A[i][j]);
printf("\n\n");
}
printf("\n");
printf("\t {matrik.B}\n");
printf("\n");

garis();
//tampilan matrik B

printf("\n");
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
printf("%6i",B[i][j]);
printf("\n\n");
}
printf("\n");
printf("-------{ matrik..A+B }-------\n\n");
printf("\n");

garis();
//tampilan hasil penjumlahan matriks A & matriks B

printf("\n");
printf("=============================\n\n");
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
printf("%6i",X[i][j]);
printf("\n\n");
}
printf("=============================\n\n");

garis();

//selamat mencoba
//by; aqim
//ahmadmustaqim@aim.com
//www.ahmadmustaqim.tk
getch();
}

0 komentar:

Post a Comment

Followers