Contoh Soal C++

Posted: May 10, 2011 in Bahasa C++

Buat program jumlah anak ayam diinputkan (n), lalu tampilkan :

Anak ayam turun n, mati satu tinggal n-1
Anak ayam turun 0, mati satu tinggal induknya

penyelesaian nya :

#include
#include
using namespace std;

int main()
{
clrscr();
int x, y;
cout <> x;
for (y=x; y>=1; y–)
{if (y==1) {
cout << “Anak ayam turun ” << y << “, mati satu tinggal induknya ”
<<endl;}
else {
cout << “Anak ayam turun ” << y << “, mati satu tinggal ” << y-1
<<endl;}
}getch();
}

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