Friday, 27 October 2017

Program C++ Anak Ayam (For, While, Do…While)

DO-WHILE:

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

using namespace std;
int main()
{ int am;

cout<<"Anak ayam turunlah  : ";cin>>am;
cout<<"Tek Kotek Kotek Kotek Anak Ayam Turun Berkotek 2x "<<endl;
//am--;
do
{

cout<<"Anak Ayam Turunlah "<<am <<" Mati Satu Tinggallah  "<<am-1<<endl;
am--;
}
while (am>2);
cout<<"Mati satu tinggal induknya"<<endl;
getch();
return 0;
}




WHILE:

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

using namespace std;
int main()
{ int am;

cout<<"Anak ayam turunlah  : ";cin>>am;
cout<<"Tek Kotek Kotek Kotek Anak Ayam Turun Berkotek 2x "<<endl;
//am--;
while (am>2)
{

cout<<"Anak Ayam Turunlah "<<am <<" Mati Satu Tinggallah  "<<am-1<<endl;
am--;
}
cout<<"Mati satu tinggal induknya"<<endl;
getch();
return 0;
}


FOR:

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

using namespace std;
int main()
{ int am;

cout<<"Anak ayam turunlah  : ";cin>>am;
cout<<"Tek Kotek Kotek Kotek Anak Ayam Turun Berkotek 2x "<<endl;
for (am; am>2; am--){

cout<<"Anak Ayam Turunlah "<<am <<" Mati Satu Tinggallah "<<am-1<<endl;
}
cout<<"Mati satu tinggal induknya"<<endl;
getch();
return 0;
}


No comments:

Post a Comment