A. Mencetak Bilangan 1 - 10 Menggunakan Perulangan For,
While, dan Do While,
1. Perulangan For
for (int i=1; i<=10; i++){
cout<<"i ="<<i;
}
2. Perulangan While
int i=1;
while(i<=10){
cout<<" i ="<<i;
i++
}
3. Perulangan Do While
int i=1;
do {
cout<<" i ="<<i;
i++
} while (1<=10)
B. Fungsi dan Template
1. Fungsi
int hitunglah(int a, int b) {
total=0;
for ( int i=1; i<=10; i++ ) {
total=total+i;
return total;
}
}
2. Template
1. Perulangan For
for (int i=1; i<=10; i++){
cout<<"i ="<<i;
}
2. Perulangan While
int i=1;
while(i<=10){
cout<<" i ="<<i;
i++
}
3. Perulangan Do While
int i=1;
do {
cout<<" i ="<<i;
i++
} while (1<=10)
B. Fungsi dan Template
1. Fungsi
int hitunglah(int a, int b) {
total=0;
for ( int i=1; i<=10; i++ ) {
total=total+i;
return total;
}
}
2. Template
Template
(Class T)
T hitunglah ( T a, T b) {
total=0;
for ( T a=1; a<=10; a++ ) {
total = total+1;
return total;
}
}
Tidak ada komentar:
Posting Komentar