Upload presentasi
Presentasi sedang didownload. Silahkan tunggu
1
contoh aplikasi array 2 dimensi
sedikit contoh aplikasi array 2 dimensi
2
Contoh-1 Magic Square (bujur sangkar ajaib)
3
8 1 6 3 5 7 4 9 2 Magic square 15 15 15 15 15 15 Square Matrix 3x3
n = 3 15 15 8 1 6 3 5 7 4 9 2 15
4
8 1 6 3 5 7 4 9 2 Magic square 15 15 15 15 15 15 Square Matrix 3x3
n = 3 15 8 1 6 ( n3 + n ) / 2 = 3 5 7 ( ) / 2 = ( ) / 2 = 15 4 9 2 15 (nxn/2) x (nxn +1) / n = (3x3/2) x (3x3 + 1) / 3 = ( ) x ( ) / 3 = 15
5
Magic square Square Matrix 5x5 65 n = 5 ( n3 + n ) / 2 =
( ) / 2 = ( ) / 2 = 65 65 (nxn/2) x (nxn +1) / n = (5x5/2) x (5x5 + 1) / 5 = ( ) x ( ) / 5 = 65
6
Magic square Square Matrix 11x11 n = 11 ( n3 + n ) / 2 =
671 Square Matrix 11x11 n = 11 ( n3 + n ) / 2 = ( ) / 2 = ( ) / 2 = 671 671
7
#include<stdio.h>
void main() { int A[21][21]={0}; int n,i,j,r,c,key; printf("input n, positip, ganjil, minimum 3, maksimum 11\n"); scanf("%i", &n); key=1;i=0; j=(n-1)/2; A[i][j]=key; key++; while(key<=n*n) { r=(i+n-1)%n; c=(j+n-1)%n; if(A[r][c] != 0 ) { i=(i+1)%n; } else { i=r; j=c; } A[i][j]=key; key++; } for(i=0;i<=n-1;i++) { for(j=0;j<=n-1;j++) { printf("%4i",A[i][j]); } printf("\n\n");
9
Magic square Square Matrix 11x11 n = 11
11
eliminasi Gauss Jordan
13
Diketahui Sistem Persamaan Linear
sebagai berikut : Susun algoritma untuk menghitung nilai : X1 = …… X2 = …… X3 = …… X4 = ……
14
Hasil yang tercetak oleh program :
15
Periksa : 2x3 + 3x2 + 1x5 + 3x2 = 6 + 6 + 5 + 6 = 12 + 11 = 23
= = 23 3x3 + 2x2 + 2x5 + 2x2 = = = 27
16
Program : //gaus-01.cpp #include<stdio.h>
float A[4][5] = {2,3,1,3,23, 3,2,2,2,27, 1,3,3,2,28, 4,5,2,3,38}; float B[5]; int i,j,k; float x,y; void CETAK() { for(i=0; i<=3; i++ ) { printf("\n X%i = %2.1f", i+1, A[i][4] ); } void main() { for(j=0; j<=2; j++) {for(i=j+1; i<=3; i++ ) { x=A[i][j]; y=A[j][j]; for(k=0; k<=4; k++) { A[i][k] = y*A[i][k] - x*A[j][k]; } A[3][4]=A[3][4] / A[3][3]; A[3][3]=1; for(j=3; j>=1; j--) {for(i=j-1; i>=0; i-- ) { A[i][k] = y*A[i][k] - x*A[j][k]; for(i=0;i<=3;i++) { A[i][4]=A[i][4]/A[i][i]; A[i][i] = 1; } CETAK();
17
void main() { for(j=0; j<=2; j++) {for(i=j+1; i<=3; i++ ) { x=A[i][j]; y=A[j][j]; for(k=0; k<=4; k++) { A[i][k] = y*A[i][k] - x*A[j][k];} } A[3][4]=A[3][4] / A[3][3]; A[3][3]=1; for(j=3; j>=1; j--) {for(i=j-1; i>=0; i-- ) { A[i][k] = y*A[i][k] - x*A[j][k]; for(i=0;i<=3;i++) { A[i][4]=A[i][4]/A[i][i]; A[i][i] = 1; } CETAK();
18
void main() { for(j=0; j<=2; j++) {for(i=j+1; i<=3; i++ ) { x=A[i][j]; y=A[j][j]; for(k=0; k<=4; k++) { A[i][k] = y*A[i][k] - x*A[j][k];} } A[3][4]=A[3][4] / A[3][3]; A[3][3]=1; for(j=3; j>=1; j--) {for(i=j-1; i>=0; i-- ) { A[i][k] = y*A[i][k] - x*A[j][k]; for(i=0;i<=3;i++) { A[i][4]=A[i][4]/A[i][i]; A[i][i] = 1; } CETAK();
19
Program : for(j=3; j>=1; j--) {for(i=j-1; i>=0; i-- )
{ x=A[i][j]; y=A[j][j]; for(k=0; k<=4; k++) { A[i][k] = y*A[i][k] - x*A[j][k]; } for(i=0;i<=3;i++) { A[i][4]=A[i][4]/A[i][i]; A[i][i] = 1; } CETAK();
21
#include<stdio>
#include<conio.h> void main() { int A[3][5]; //menyiapkan array int I,J, N; clrscr(); // mengisi array // mencetak isi array // agar dapat dilihat apakah // mengisi array sudah benar getch(); }
22
#include<stdio> #include<conio.h> void main()
{ int A[3][5]; int I,J, N; clrscr(); // mengisi array // mencetak isi array for(I=0; I<=2; I=I+1) { for(J=0; J<=4; J=J+1) { printf(“%4i”, A[I][J]; } getch(); 1 2 3 4 5 1 2 6 7 8 9 10 11 12 13 14 15
23
#include<stdio> #include<conio.h> void main()
{ int A[3][5]; int I,J, N; clrscr(); // mengisi array N = 1; for(I=0; I<=2; I=I+1) { for(J=0; J<=4; J=J+1) { xxxxxxxxx; xxxxxxxxx; } // mencetak isi array { printf(“%4i”, A[I][J]; getch(); 1 2 3 4 5 1 2 6 7 8 9 10 11 12 13 14 15
24
#include<stdio> #include<conio.h> void main()
{ int A[3][5]; int I,J, N; clrscr(); // mengisi array N = 1; for(I=0; I<=2; I=I+1) { for(J=0; J<=4; J=J+1) { A[I][J] = N; N = N+1; } // mencetak isi array { printf(“%4i”, A[I][J]; getch(); 1 2 3 4 5 1 2 6 7 8 9 10 11 12 13 14 15
25
tidak menggunakan variabel N
26
? #include<stdio> #include<conio.h> void main()
{ int A[3][5]; int I,J; clrscr(); // mengisi array N = 1; for(I=0; I<=2; I=I+1) { for(J=0; J<=4; J=J+1) { A[I][J] = ; } // mencetak isi array { printf(“%4i”, A[I][J]; getch(); 1 2 3 4 5 1 2 6 7 8 9 10 11 12 13 14 15 ?
27
#include<stdio> #include<conio.h> void main()
{ int A[3][5]; int I,J; clrscr(); // mengisi array N = 1; for(I=0; I<=2; I=I+1) { for(J=0; J<=4; J=J+1) { A[I][J] = I*5 + J+1; } // mencetak isi array { printf(“%4i”, A[I][J]; getch(); 1 2 3 4 5 1 2 6 7 8 9 10 11 12 13 14 15
28
diisi kolom per kolom
29
{ for(I=0; I<=2; I=I+1) { }
1 2 3 4 5 diisi baris per baris 1 2 6 7 8 9 10 11 12 13 14 15 for(J=0; J<=4; J=J+1) { for(I=0; I<=2; I=I+1) { } J --> loop luar I --> loop dalam
30
#include<stdio> #include<conio.h> void main()
{ int A[3][5]; //menyiapkan array int I,J, N, K; clrscr(); // mengisi array // mencetak isi array // agar dapat dilihat apakah // mengisi array sudah benar getch(); } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
31
#include<stdio> #include<conio.h> void main()
{ int A[3][5]; int I,J, N, K; clrscr(); // mengisi array // mencetak isi array for(I=0; I<=2; I=I+1) { for(J=0; J<=4; J=J+1) { printf(“%4i”, A[I][J]; } getch(); 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
32
#include<stdio> #include<conio.h> void main()
{ int A[3][5]; int I,J, N,K; clrscr(); // mengisi array N = 1; for(J=0; J<=4; J=J+1) { K=N; for(I=0; I<=2; I=I+1) { xxxxxxxxx; xxxxxxxxx; } N=N+1; // mencetak isi array { for(J=0; J<=4; J=J+1) { printf(“%4i”, A[I][J]; getch(); 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
33
#include<stdio> #include<conio.h> void main()
{ int A[3][5]; int I,J, N,K; clrscr(); // mengisi array N = 1; for(J=0; J<=4; J=J+1) { K=N; for(I=0; I<=2; I=I+1) { A[I,J] = K; K = K : } N=N+1; // mencetak isi array { for(J=0; J<=4; J=J+1) { printf(“%4i”, A[I][J]; getch(); 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
34
#include<stdio> #include<conio.h> void main()
{ int A[3][5]; int I,J, N,K; clrscr(); // mengisi array N = 1; for(J=0; J<=4; J=J+1) { K=N; for(I=0; I<=2; I=I+1) { A[I,J] = K; K = K + 5; } N=N+1; // mencetak isi array { for(J=0; J<=4; J=J+1) { printf(“%4i”, A[I][J]; getch(); 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
35
tidak menggunakan variabel N
36
? #include<stdio> #include<conio.h> void main()
{ int A[3][5]; int I,J; clrscr(); // mengisi array for(J=0; J<=4; J=J+1) { for(I=0; I<=2; I=I+1) { A[I,J] = ; } // mencetak isi array for(I=0; I<=2; I=I+1) { for(J=0; J<=4; J=J+1) { printf(“%4i”, A[I][J]; getch(); 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ?
37
#include<stdio> #include<conio.h> void main()
{ int A[3][5]; int I,J; clrscr(); // mengisi array for(J=0; J<=4; J=J+1) { for(I=0; I<=2; I=I+1) { A[I,J] = I*5 + J+1 ; } // mencetak isi array for(I=0; I<=2; I=I+1) { for(J=0; J<=4; J=J+1) { printf(“%4i”, A[I][J]; getch(); 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
39
SOAL-2
40
Soal-2. Sudah ada array Dua Dimensi yang dibuat dengan int A[3][5], belum ada isinya . Susun program (penggalan program) untuk mengisi array tersebut sehingga isinya menjadi sebagai berikut : 1 4 7 10 13 1 2 2 5 8 11 14 3 6 9 12 15
41
diisi baris per baris atau kolom per kolom ?
Presentasi serupa
© 2024 SlidePlayer.info Inc.
All rights reserved.