Toggle navigation
Home
Latest pastes
FAQ
Random
Register
Login
Make a diamond using loops
SUBMITTED BY:
Guest
DATE:
Oct. 27, 2014, 12:23 p.m.
FORMAT:
Text only
SIZE:
1.3 kB
Raw
Download
Tweet
HITS:
774
Go to comments
Report
#include<iostream.h>
#include<conio.h>
void main()
{
int rows, b, c;
char choice;
do
{
clrscr();
cout<<"Enter number of rows \n\"Value should be > 1\" \n";
cin>>rows;
cout<<endl;
for (int dash=1; dash<=80; dash++)
{
cout<<"-";
}
cout<<endl;
for (b=1; b<=rows; b++)
{
for (c=rows; c>=b; c--)
{
cout<<"*";
}
for (c=1; c<=(b*2)-2; c++)
{
cout<<" ";
}
for (c=rows; c>=b; c--)
{
cout<<"*";
}
cout<<endl;
}
/*---------------------------*/
for (b=1; b<=rows; b++)
{
for (c=1; c<=b; c++)
{
cout<<"*";
}
for (c=rows; c>=(b*2)-(rows-1); c--)
{
cout<<" ";
}
for (c=1; c<=b; c++)
{
cout<<"*";
}
cout<<endl;
}
cout<<endl;
for (int dash=1; dash<=80; dash++)
{
cout<<"-";
}
cout<<endl;
cout<<"Press Y to start again.";
cin>>choice;
}
while (choice=='Y' || choice=='y');
}
Please enable JavaScript to view the
comments powered by Disqus.
comments powered by
Disqus