Perulangan Dengan FOR, WHILE, DO-WHILE (cpp, C++)
Perulangan C++ Dengan For,While, dan Do-While
Hei Agan2, Sist, Boy, Girl, Bor.... Blogger yang setia...kali ini ane mau share tentang cara menggunakan perulangan dalam bahasa c++ menggunakan For, While, dan Do-While...
- Perulangan Menggunakan FOR
oke, langsung aje liat ni coding, menggunakan MinGW.. :v ;
#include <iostream.h>
#include <conio.h>
using namespace std;
main ()
{
int a;
system ("title FOR #apps by edy");
system ("color f9");
cout<<endl;
cout<<" latihan for by: edy, 140xxx060 :D"<<endl;
cout<<"==============================================================================="<<endl;
cout<<endl;
cout<<"1. menampilkan deret bilangan dari 1 ~ 20 = ";
for (a=1;a<=20;a++)
{cout<<a<<' ';}
cout<<endl;
cout<<endl;
cout<<"2. menampilkan bilangan ganjil dari 1 ~ 20 = ";
for (a=0;a<20;a++)
{a%2==0;
cout<<a+1<<' ';
a++;}
cout<<endl;
cout<<endl;
cout<<"3. menampilkan bilangan genap dari 1 ~ 20 = ";
for (a=2;a<=20;a++)
{a%2==0;
cout<<a<<' ';
a++;}
cout<<endl;
cout<<endl;
cout<<"==============================================================================="<<endl;
getche ();
}
atau kalau agan2 ngk mau repot, langsung aja download disini!!!
- Perulangan Menggunakan WHILE
oke, langsung aje liat ni coding, menggunakan MinGW.. :v ;
#include <iostream.h>#include <conio.h>using namespace std;main (){int a=1,b=0,c=0;system ("title WHILE #apps by edy");system ("color f9");cout<<endl;cout<<" latihan while by: edy.. 140170xxx :v"<<endl;cout<<"================================================================================"<<endl;cout<<endl;
cout<<"1. menampilkan deret bilangan 1 ~ 14 = ";while (a<=14){cout<<a<<' ';a++;}cout<<endl;cout<<endl;
cout<<"2. menampilkan bilangan ganjil dari 1 ~ 20 = ";while (b<20){b=b+1;cout<<b<<' ';b++;} cout<<endl;cout<<endl;
cout<<"3. menampilkan bilangan genap dari 1 ~ 20 = ";while (c<20){c=c+2;cout<<c<<' ';}cout<<endl;cout<<endl;
cout<<"================================================================================"<<endl;getche ();}
atau kalau agan2 ngk mau repot, langsung aja download disini!!!
oke, langsung aje liat ni coding, menggunakan MinGW.. :v ;
#include <iostream.h>#include <conio.h>using namespace std;main (){int a=1,b=0,c=0;system ("title WHILE #apps by edy");system ("color f9");cout<<endl;cout<<" latihan while by: edy.. 140170xxx :v"<<endl;cout<<"================================================================================"<<endl;cout<<endl;
cout<<"1. menampilkan deret bilangan 1 ~ 14 = ";while (a<=14){cout<<a<<' ';a++;}cout<<endl;cout<<endl;
cout<<"2. menampilkan bilangan ganjil dari 1 ~ 20 = ";while (b<20){b=b+1;cout<<b<<' ';b++;} cout<<endl;cout<<endl;
cout<<"3. menampilkan bilangan genap dari 1 ~ 20 = ";while (c<20){c=c+2;cout<<c<<' ';}cout<<endl;cout<<endl;
cout<<"================================================================================"<<endl;getche ();}
- Perulangan Menggunakan DO-WHILE
oke, langsung aje liat ni coding, menggunakan MinGW.. :v ;
#include <iostream.h>
#include <conio.h>
using namespace std;
main()
{
int q=1,w=0,e=0;
system ("title DO-WHILE #apps by edy");
system ("color f9");
cout<<endl;
cout<<" latihan do-while by: edy.. xxx170060 :)"<<endl;
cout<<"================================================================================"<<endl;
cout<<endl;
cout<<"1. menampilkan deret bilangan 1 ~ 14 = ";
do
{ cout<<q<<' ';
q++;}
while (q<=14);
cout<<endl;
cout<<endl;
cout<<"2. menampilkan bilangan ganjil dari 1 ~ 20 = ";
do
{w=w+1;
cout<<w<<' ';
w++;}
while (w<20);
cout<<endl;
cout<<endl;
cout<<"3. menampilkan bilangan genap dari 1 ~ 20 = ";
do
{e=e+2;
cout<<e<<' ';}
while (e<20);
cout<<endl;
cout<<endl;
cout<<"================================================================================"<<endl;
getche ();
}
atau kalau agan2 ngk mau repot, langsung aja download disini!!!
Sekian dulu posting dari ane....semoga bermanfaat dan terima kasih.......................................
oke, langsung aje liat ni coding, menggunakan MinGW.. :v ;
#include <iostream.h>
#include <conio.h>
using namespace std;
main()
{
int q=1,w=0,e=0;
system ("title DO-WHILE #apps by edy");
system ("color f9");
cout<<endl;
cout<<" latihan do-while by: edy.. xxx170060 :)"<<endl;
cout<<"================================================================================"<<endl;
cout<<endl;
cout<<"1. menampilkan deret bilangan 1 ~ 14 = ";
do
{ cout<<q<<' ';
q++;}
while (q<=14);
cout<<endl;
cout<<endl;
cout<<"2. menampilkan bilangan ganjil dari 1 ~ 20 = ";
do
{w=w+1;
cout<<w<<' ';
w++;}
while (w<20);
cout<<endl;
cout<<endl;
cout<<"3. menampilkan bilangan genap dari 1 ~ 20 = ";
do
{e=e+2;
cout<<e<<' ';}
while (e<20);
cout<<endl;
cout<<endl;
cout<<"================================================================================"<<endl;
getche ();
}
Comments
Post a Comment