Larik - Ari

  • June 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Larik - Ari as PDF for free.

More details

  • Words: 582
  • Pages: 7
LARIK / ARRAY LARIK menyatakan KUMPULAN DATA YANG BERTIPE SAMA contoh : Larik A 1

2

3

4

0

1

2

3

indeks

Deklarasi Larik : tipe nama [jumlah_elemen] int cacah[4] ; mempunyai 4 buah elemen bertipe integer char vokal[5] ; tipe character dengan 5 buah elemen char kota[6][20] ; tipe character panjang max 20 , 6 elemen pengaksesan array dimulai dari 0 contoh : int jumlah_hari[9] = {10, 2, 3, 4, 5, 6, 7, 8, 90} maka : jum_hari[0] bernilai jum_hari[1] bernilai jum_hari[2] bernilai jum_hari[3] bernilai jum_hari[4] bernilai jum_hari[5] bernilai jum_hari[6] bernilai jum_hari[7] bernilai jum_hari[8] bernilai

10 2 3 4 5 6 7 8 90

Menampilkan Larik Algoritma Deklarasi char kar[n]; integer indeks; Deskripsi for ( indeks = 0 to n step 1) write (kar[n]);

Pemrograman C++ #include int main() { char kar[5] = {‘A’ , ‘I’, ‘E’, ‘O’, ‘U’} ; int i ; for ( i = 0 ; i<5 ; i++) cout << kar[i] <<”\n” ;

endfor

return 0; } ATAU #include int main() { char kar[5] ; int i ; kar[0] = ‘A’ ; kar[1] = ‘I’ ; kar[2] = ‘E’ ; kar[3] = ‘O’ ; kar[4] = ‘U’ ; for ( i = 0 ; i<5 ; i++) cout << kar[i] <<”\n” ; return 0;

MENGISI LARIK Algoritma Deklarasi char kar[n]; integer indeks; Deskripsi for ( indeks = 0 to n step 1) write (“Masukkan Karakter”); read (kar[n]) ;

Pemrograman C++ #include int main() { char kar[5]; int i ; for ( i = 0 ; i<5 ; i++) { cout << “Masukkan Karakter” <<”\n” ; cin << “ kar[i] ; } cout << kar[i] <<”\n”;

end for read (“kar[n]) ; endfor

for ( i = 0 ; i<5 ; i++) cout << kar[i] <<”\n” ; return 0; }

MENCARI BILANGAN TERBESAR Deklarasi integer data[n]; integer indeks; integer terbesar; Deskripsi terbesar = data[0] for ( indeks = 0 to n step 1) if (data[indeks] > terbesar) then terbesar = data[indeks] end if

Pemrograman C++ #include int main() { int data[5] ={7, 4, 9, 2, 8}; int i ; int terbesar; terbesar = data[0]; for ( i = 0 ; i<5 ; i++) { if (data[i] > terbesar) terbesar = data[i]; } cout << “Bilangan Terbesar << terbesar << “\n”;

end for write (“Bilangan terbesar” , terbesar); }

KODE DAN NAMA BULAN Algoritma

Pemrograman C++

Deklarasi

#include

karakter nama_bulan[][10] = {“”, “Januari”, “Februari”, “Maret”, “April”, “Mei”, “Juni”, int main() “Juli”, “Agustus”, “September”, { “Oktober”, “November”, “Desember”} char nama_bulan[][10] ={“”, “Januari”, “Februari”, “Maret”, “April”, “Mei”, “Juni”, “Juli”, “Agustus”, integer kode_bulan; “September”, “Oktober”, “November”, “Desember”}; write (“Kode bulan (1..12)”); read (kode_bulan);

int kode_bulan ; cout << “Kode bulan (1..12) : “ ; cin >> kode_bulan;

if(kode_bulan >= 1 && kode_bulan <= 12) write(“Bulan :” , nama_bulan[kode_bulan]); else write (“Kode mesti 1 sampai 12”);

if (kode_bulan >= 1 && kode_bulan <= 12) cout << “ Bulan : “ << nama_bulan[kode_bulan] << “\n” ; else cout << ” Kode mesti 1 sampai 12 \n“ ; }

Algoritma Pemrograman C++ #include int main() { int data[] = {8, 9, 4,7,6}; int i; for (i= 4 ; i>0 ; i--) cout << data [i] <<” “ ; cout << “\n”; }

MENGGABUNG LARIK

Pemrograman C++ #include int main() { int a[6] = {1, 2, 3,4,5, 6} ; int b[6] = {7, 8, 9,10,11, 12} ; int c[6] ; int i; for (i= 0 ; i<=5 ; i--) cout << data [i] <<” “ ; cout << “\n”;

Related Documents

Larik - Ari
June 2020 11
Larik - Ari
June 2020 13
Larik
December 2019 29
Ari
August 2019 22
Ari
May 2020 20
Ari
April 2020 14