Mesran

Hanya ingin berbagi kebaikan dan mendapatkan kebaikan yang lain.

Latihan Array Dimensi 2 : Penambahan Matrik

Nah pada latihan Array Dimensi 2 ini kita akan membahas program penambahan Matrik

Ketikkanlah program di bawah ini :

#include “conio.h”
#include “iostream.h”
#include “string.h”
void main() {

int A[3][3] ;
int B[3][3] ;
int C[3][3] ;
int i, j ;
int x ;

x = 1 ;

//untuk menginputkan Matrik A
gotoxy(10,1) ; cout<< “Inputkan Matrik A”  ;
for(i=0 ; i<3 ; i++){
for(j=0 ; j<3 ; j++){
gotoxy(10,2+x) ; cout<< “A[” << i <<“,”<<j<<“] :” ; cin>>A[i][j] ;
x++ ;
}
}

//untuk menginputkan Matrik B
x = 1 ;
gotoxy(40,1) ; cout<< “Inputkan Matrik B”  ;
for(i=0 ; i<3 ; i++){
for(j=0 ; j<3 ; j++){
gotoxy(40,2+x) ; cout<< “B[” << i <<“,”<<j<<“] :” ; cin>>B[i][j] ;
x++ ;
}
}

//Proses Matrik C
for(i=0 ; i<3 ; i++){
for(j=0 ; j<3 ; j++){
C[i][j] = A[i][j] + B[i][j] ;
}
}

//untuk menampilkan Matrik C
x = 1 ;
gotoxy(60,1) ; cout<< “Matrik C”  ;
for(i=0 ; i<3 ; i++){
for(j=0 ; j<3 ; j++){
gotoxy(60,2+x) ; cout<< “C[” << i <<“,”<<j<<“] :” << C[i][j] ;
x++ ;
}
}

}

Hasil Program akan terlihat seperti berikut ini :

Selamat Mencoba!


#include “conio.h”
#include “iostream.h”
#include “string.h”
void main() {
int A[3][3] ;
int B[3][3] ;
int C[3][3] ;
int i, j ;
int x ; 

x = 1 ;
gotoxy(10,1) ; cout<< “Inputkan Matrik A”  ;
for(i=0 ; i<3 ; i++){
for(j=0 ; j<3 ; j++){
gotoxy(10,2+x) ; cout<< “A[” << i <<“,”<<j<<“] :” ; cin>>A[i][j] ;
x++ ;
}
}
x = 1 ;
gotoxy(40,1) ; cout<< “Inputkan Matrik B”  ;
for(i=0 ; i<3 ; i++){
for(j=0 ; j<3 ; j++){
gotoxy(40,2+x) ; cout<< “B[” << i <<“,”<<j<<“] :” ; cin>>B[i][j] ;
x++ ;
}
}

//Proses Matrik C
for(i=0 ; i<3 ; i++){
for(j=0 ; j<3 ; j++){
C[i][j] = A[i][j] + B[i][j] ;
}
}
x = 1 ;
gotoxy(60,1) ; cout<< “Matrik C”  ;
for(i=0 ; i<3 ; i++){
for(j=0 ; j<3 ; j++){
gotoxy(60,2+x) ; cout<< “C[” << i <<“,”<<j<<“] :” << C[i][j] ;
x++ ;
}
}
}

Filed under: C/C++,

Terima kasih telah memberikan komentar anda.

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

Archives Per Tahun

Sponsored

C&C Online Shop

Blog Stats

  • 355,762 sejak 12 Jan 2011

User’s Online


My Music

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 223 other followers

March 2011
M T W T F S S
« Feb   Apr »
 123456
78910111213
14151617181920
21222324252627
28293031  
%d bloggers like this: