Struktur Data 3 : Looping and Array

Pertemuan Ketiga kali ini membahas Jenis-Jenis Perulangan & Array.
clip_image00213

1. 3 Jenis Perulangan C++

  • For

Mencetak bilangan 10 sampai 1.
Void cetaklah(int i, int j){
int i=10;
int j=1;

for(i=10;i>=j;i–){
cout<<i;

}

  • Do…while

Mencetak bilangan 10 sampai 1.
void cetaklah(int i, int j){
int i=10;
int j=1;

do{
cout<<i;
}

while(i>j){
cout<<“Selesai”;
}

  • While

Mencetak bilangan 10 sampai 1.
void cetaklah(int a, int b){
int i=a;
while(i>=b){
cout<<” I = “<<i;
}

2. Array

void masukandata(int A[], int n){
for(int i=0;i<=n;i++){
cout<<“Masukan Data ke”<<i+1;
cin>>A[i];
}

int jumlahkan(const int A[], int n){
int total=0;
for(int=0;i<n;i++){
total += A[i];
return total;
}

Advertisements

Leave a Reply

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