Membuat program untuk menampilkan deret angka dengan pola tampilan berupa bermacam-macam model segitiga seperti berikut :
Contoh 1:
using namespace std;
int main()
{
for(int x = 1; x <= 5; x++)
{
for(int y = 0; y < x; y++)
{
cout<<x + y<<" ";
}
cout<<endl;
}
return 0;
}
Contoh 2:
using namespace std;
int main()
{
for(int x = 5; x > 0; x--)
{
for(int y = 0; y < x; y++)
{
cout<<x<<" ";
}
cout<<endl;
}
return 0;
}
Contoh 3:
using namespace std;
int main()
{
for(int a = 0; a < 10; a+=2)
{
for(int b = 8; b > a; b--)
cout<<" ";
for(int c = a; c >= 0; c--)
cout<<"x ";
cout<<endl;
}
return 0;
}
No comments:
Post a Comment