nama :rheza ariyanto kelas :tkj 1b · kelas :tkj 1b . latihan soal 1.a. bahasa c++ #include ...

Post on 07-Mar-2019

234 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Latihan 4 Looping

Nama :Rheza Ariyanto

Kelas :TKJ 1B

Latihan Soal 1.A

Bahasa C++

#include <iostream>

#include <iomanip.h>

using namespace std;

main ()

{

int p, q, r;

p=5;

cout<<"Latihan Soal 1.a\n\n";

for (q=p; q>=2; q--)

{

cout<<setw(q);

for (r=q; r<=p; r++)

{

cout<<"*";

}

for (r=q+1; r<=p; r++)

{

cout<<"*";

}

cout<<'\n';

}

for (q=3; q<=p; q++)

{

cout<<setw(q);

for (r=p; r>=q; r--)

{

cout<<"*";

}

for (r=p-1; r>=q; r--)

{

cout<<"*";

}

cout<<'\n';

}

cout<<'\n';

system ("pause");

return 0;

}

Hasilnya

Latihan Soal 1.B

Bahasa C++

#include <iostream>

#include <iomanip.h>

using namespace std;

main ()

{

int p, q, r;

p=5;

cout<<"Latihan Soal 1.b\n\n";

for (q=p; q>=2; q--)

{

cout<<setw(q);

for (r=q; r<=p; r++)

{

cout<<"*";

}

for (r=q+1; r<=p; r++)

{

cout<<"*";

}

cout<<'\n';

}

cout<<'\n';

system ("pause");

return 0;

}

Hasilnya

Latihan Soal 1.C

Bahasa C++

#include <iostream>

#include <iomanip.h>

using namespace std;

main ()

{

int p, q, r;

p=5;

cout<<"Latihan Soal 1.c\n\n";

for (q=p; q>=2; q--)

{

for (r=q; r<=p; r++)

{

cout<<"*";

}

for (r=q+1; r<=p; r++)

{

cout<<"*";

}

cout<<'\n';

}

for (q=3; q<=p; q++)

{

for (r=p; r>=q; r--)

{

cout<<"*";

}

for (r=p-1; r>=q; r--)

{

cout<<"*";

}

cout<<'\n';

}

cout<<'\n';

system ("pause");

return 0;

}

Hasilnya

top related