TUGAS LOOPING
Contoh Program :
//Membuat Looping Dengan Bintang
#include <iostream>
using namespace std;
int tempe,ayam;
int a,b,i,j,abc,cd;
int main(){
cout << " Looping Persegi Bentuk Bintang"<<endl;
cout<<endl;
i =1;
while(i<11){
j = 1;
while (j<11){
cout << " * ";
j++;
}
cout<<endl;
i++;
}
cout << " Looping Persegi Perpaduan Angka dan Bintang"<<endl;
cout<<endl;
i=1;
while (i<=9){
j=1;
while(j<=9){
if(i==j){
cout << "*";
}
else{
cout <<j<<" ";
}
j++;
}
i=i+1;
cout << endl;
}
cout << " Looping Persegi Setengah Bintang Setengah Angka"<<endl;
cout<<endl;
i=1;
while(i<9){
j =1;
while(j < 9){
if(i>=j){
cout << "* ";
}
else{
cout <<j<< " ";
}
j++;
}
cout<< endl;
i++;
}
cout << " Looping Segitiga Angka"<<endl;
cout<<endl;
i=11;
while(i>1){
j=11;
while(j>=i){
cout << j << " ";
j--;
}
cout << endl;
i--;
}
cout << " Looping Segitiga Bintang Terbalik"<<endl;
cout<<endl;
tempe=11;
while(ayam>1){
ayam=11;
do{
cout << " * ";
tempe=tempe-1;
}while (tempe>ayam-1);
cout << endl;
ayam=ayam-1;
}
abc = 1;
while(abc<11)
{
cd = 11;
do
{
cout <<"*";
cd = cd - 1;
}while(abc<cd);
cout<<endl;
abc = abc + 1;
}
cout << " Looping segitiga Berhadapan " << endl;
cout<<endl;
b = 1;
while (b >1)
{
a = 10;
do
{
cout << " * " ;
a = a + 1;
} while (a < b);
cout << endl;
b = b -1;
}
b=10;
while(b>0)
{
a = 1;
do{
cout <<" * ";
a=a+1;
}
while(a<=b);
b=b-1;
cout <<endl;
}
b=1;
while(b<11)
{
a = 1;
do{
cout <<" * ";
a=a+1;
}
while(b>=a);
b=b+1;
cout <<endl;
}
}
Hasil Running Program Diatas :
.png)
.png)
.png)
Komentar
Posting Komentar