Contoh Program Pengaplikasian Looping

Setelah beberapa kali mencoba, akhirnya bisa juga membuat program yang keluarannya seperti berikut ini walau awalnya sempet bingung!

berikut ini adalah contoh codenya:

#include <iostream>
#include <conio.h>

using namespace std;

main(){
 int x;
int y;
cout<<"Masukkan input (maksimal 10): ";
cin>>y;
for(x=9;x<=y;x++) if(x<y) cout<<"*";cout<<endl;
for(x=8;x<=y;x++) if(x<y) cout<<"*";cout<<endl;
for(x=7;x<=y;x++) if(x<y) cout<<"*";cout<<endl;
for(x=6;x<=y;x++) if(x<y) cout<<"*";cout<<endl;
for(x=5;x<=y;x++) if(x<y) cout<<"*";cout<<endl;
for(x=4;x<=y;x++) if(x<y) cout<<"*";cout<<endl;
for(x=3;x<=y;x++) if(x<y) cout<<"*";cout<<endl;
for(x=2;x<=y;x++) if(x<y) cout<<"*";cout<<endl;
for(x=1;x<=y;x++) if(x<y) cout<<"*";cout<<endl;
for(x=0;x<=y;x++) if(x<y) cout<<"*";cout<<endl;
for(x=1;x<=y;x++) if(x<y) cout<<"*";cout<<endl;
for(x=2;x<=y;x++) if(x<y) cout<<"*";cout<<endl;
for(x=3;x<=y;x++) if(x<y) cout<<"*";cout<<endl;
for(x=4;x<=y;x++) if(x<y) cout<<"*";cout<<endl;
for(x=5;x<=y;x++) if(x<y) cout<<"*";cout<<endl;
for(x=6;x<=y;x++) if(x<y) cout<<"*";cout<<endl;
for(x=7;x<=y;x++) if(x<y) cout<<"*";cout<<endl;
for(x=8;x<=y;x++) if(x<y) cout<<"*";cout<<endl;
for(x=9;x<=y;x++) if(x<y) cout<<"*";cout<<endl;

getch();
}

jika cara ini terlalu rumit mohon dimaklumi, karena saya baru belajar!

Terimakasih!!

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