Simple Program to make a triangle with a space in it
here is the code:
#include <iostream.h>
#include <conio.h>
#include <stdio.h>
using namespace std;
int main()
{
int a,x,y;
do
{
cout<<"Put an odd number = ";cin>>a;
system("cls");
}
while (a%2==0);
for (x=1;x<=a;x++)
{
for (y=1;y<=a*2-1;y++)
{
if(x<a && y<a-x+1)
{
cout<<" ";
}
else if (x<a && y>a+x-1)
{
cout<<" ";
}
else
{
if (x%2==0)
{
if (y % 2!=0) cout<<" ";
else cout<<"*";
}
else if (x % 2!=0)
{
if (y%2 ==0) cout<<" ";
else cout<<"*";
}
}
}
cout<<endl;
}
system("pause");
}
0 komentar:
Posting Komentar