Mesran

Hanya ingin berbagi kebaikan dan mendapatkan kebaikan yang lain.

Latihan : Array pada C/C++

Pada bagian ini kita akan latihan Array Dimensi 1. Ketikkanlah program berikut ini :

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

int kode[10] ;
char nama[20];
int i ;

for(i=0 ; i<10 ; i++){
clrscr() ;
gotoxy(30,4) ; cout<< “Inputkan Kode Produk[1,2,3]”  ;
gotoxy(30,5) ; cout<< “—————————”  ;
gotoxy(30,6) ; cout<< “Kode  : ”  ;
cin >> kode[i] ;
}
clrscr()
gotoxy(10,4) ; cout<< “———————————-”  ;
gotoxy(10,5) ; cout<< “No Kode   Nama”  ;
gotoxy(10,6) ; cout<< “———————————-”  ;
for(i=0 ; i<10 ; i++){
if(kode[i]==1) strcpy(nama,”TV Sony”) ;
else if(kode[i]==2) strcpy(nama,”DVD”) ;
else if(kode[i]==3) strcpy(nama,”CD Blank”) ;
else strcpy(nama,”—-“) ;

gotoxy(10,6+i) ; cout<< i << ”  ” << kode[i] ;
gotoxy(19,6+i) ; cout<< nama ;
}
gotoxy(10,7+i) ; cout<< “———————————-”  ;

}

Saat program akan dijalankan akan muncul hasil seperti ini :

Tahapan Input Data

Tahapan Output Data

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,907 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: