Cara membuat bentuk-bentuk variasi segitiga menggunakan bahasa pemograman C++.
1.Segitiga Siku-Siku.
Coding :
#include <iostream.h>
#include <conio.h>
main()
{
int a,b,x;
cout<<"Masukkan Nilai x : ";cin>>x;
cout<<endl;
for(a=1;a<=x;a++)
{
for(b=1;b<=a;b++)
{
cout<<"*";
}
cout<<endl;
}
getch();
}
2.Segitiga Siku-Siku Terbalik.
Coding :
#include <iostream.h>
#include <conio.h>
main()
{
int a,b,x;
cout<<"Masukkan Nilai x : ";cin>>x;
cout<<endl;
for(a=1;a<=x;a++)
{
for(b=x;b>=a;b--)
{
cout<<"*";
}
cout<<endl;
}
getch();
}
3.Segitiga Sama Kaki.
Coding :
#include <iostream.h>
#include <conio.h>
main()
{
int a,b,x;
cout<<"Masukkan Nilai x : ";cin>>x;
cout<<endl;
for(a=1;a<=x;a++)
{
for(b=x;b>=a;b--)
{
cout<<" ";
}
for(b=1;b<=a+(a-1);b++)
{
cout<<"*";
}
cout<<endl;
}
getch();
}
4.Segitiga Sama Kaki Terbalik
Coding :
#include <iostream.h>
#include <conio.h>
main()
{
int a,b,x;
cout<<"Masukkan Nilai x : ";cin>>x;
cout<<endl;
for(a=1;a<=x;a++)
{
for(b=1;b<=a;b++)
{
cout<<" ";
}
for(b=0;b<=(x-a);b++)
{
cout<<"*";
}
for(b=1;b<=(x-a);b++)
{
cout<<"*";
}
cout<<endl;
}
getch();
}
1.Segitiga Siku-Siku.
Coding :
#include <iostream.h>
#include <conio.h>
main()
{
int a,b,x;
cout<<"Masukkan Nilai x : ";cin>>x;
cout<<endl;
for(a=1;a<=x;a++)
{
for(b=1;b<=a;b++)
{
cout<<"*";
}
cout<<endl;
}
getch();
}
2.Segitiga Siku-Siku Terbalik.
Coding :
#include <iostream.h>
#include <conio.h>
main()
{
int a,b,x;
cout<<"Masukkan Nilai x : ";cin>>x;
cout<<endl;
for(a=1;a<=x;a++)
{
for(b=x;b>=a;b--)
{
cout<<"*";
}
cout<<endl;
}
getch();
}
3.Segitiga Sama Kaki.
Coding :
#include <iostream.h>
#include <conio.h>
main()
{
int a,b,x;
cout<<"Masukkan Nilai x : ";cin>>x;
cout<<endl;
for(a=1;a<=x;a++)
{
for(b=x;b>=a;b--)
{
cout<<" ";
}
for(b=1;b<=a+(a-1);b++)
{
cout<<"*";
}
cout<<endl;
}
getch();
}
4.Segitiga Sama Kaki Terbalik
Coding :
#include <iostream.h>
#include <conio.h>
main()
{
int a,b,x;
cout<<"Masukkan Nilai x : ";cin>>x;
cout<<endl;
for(a=1;a<=x;a++)
{
for(b=1;b<=a;b++)
{
cout<<" ";
}
for(b=0;b<=(x-a);b++)
{
cout<<"*";
}
for(b=1;b<=(x-a);b++)
{
cout<<"*";
}
cout<<endl;
}
getch();
}
0 comments:
Post a Comment