Algoritma dan Pemrograman Mencari Transpose Matrik
Nama Kelompok :
Nama Kelompok :
Andhika
Firmanto (D1041141053)
Mahmud
Syafi’ie (D1041141001)
Yulizar
Pribadi (D1041141057)
Soal
:
Buatlah
algoritma untuk menentukan transpose matrik dibawah ini, jika diketahui :
Jawaban
:
A. Algoritma Pada
Transpose Matrik
[1] [1] ← 1
[1] [2] ← 2
[1] [3] ← 3
[1] [4] ← 4
[2] [1] ← 5
[2] [2] ← 6
[2] [3] ← 7
[2] [4] ← 8
[3] [1] ← 1
[3] [2] ← 3
[3] [3] ← 5
[3] [4] ← 7
for x ← 1 to 3 do
begin
for y ← 1 to 4 do
begin
b [y , x] ← a [x , y]
end
end
for
x
begin
for y
output a [x , y]
end
for
y
begin
for x
output b [y , x]
end
|
B. Source Code
Program Mencari Transpose Matrik Menggunakan Bahasa C :
#include <stdio.h>
#include <stdlib.h>
void main()
{
int a[3][4], b[4][3], x, y;
//Input Matriks A
printf("Masukan Matriks A\n");
printf("------------------\n");
for(x=0;x<3;x++)
{
for(y=0;y<4;y++)
{
printf("[%x][%x]: ",x+1,y+1);
scanf("%x",&a[x][y]);
}
}
printf("\n\n");
//Proses transpose
for (x=0; x<3; x++)
{
for(y=0; y<4; y++)
{
b[y][x]=a[x][y];
}
}
//Matriks A
printf("Matriks A \n");
printf("------------------\n");
for(x=0;x<3;x++)
{
for(y=0;y<4;y++)
{
printf("%3x",a[x][y]);
}
printf("\n");
}
printf("\n\n");
//Matriks B
printf("Matriks B \n");
printf("------------------\n");
for(y=0;y<4;y++)
{
for(x=0;x<3;x++)
{
printf("%3x",b[y][x]);
}
printf("\n");
}
printf("\n");
}
|
No comments:
Post a Comment