Tuesday, 13 August 2013

Hollow Diamond 2

Hollow Diamond 2:

In this post of shapes in c, you will find the code of second hollow diamond problem in C++ using "*".

Code:

/* Join us at 
http://shapesinc.blogspot.com 
for more codes of shapes */
#include<iostream>
using namespace std;
int main()
{
cout << "Join http://shapesinc.blogspot.com for more codes of shapes\n\n";
 cout<<"CAUTION:   The input should not be other than numerical values \n\n\a";  
int height=0;
cout << "Enter the length of the hollow diamond\n";
cin>>height;
//for upper side
for(int upperrows=0; upperrows<height; upperrows++)
{
for(int stars1=height; upperrows<stars1; stars1--)
cout<<"*";
for(int space1=0; space1<2*upperrows; space1++)
cout<<" ";
for(int stars2=height; upperrows<stars2; stars2--)
cout<<"*";
cout<<endl;
}
//for lower side
for(int lowerrows=0, k=height; lowerrows<height-1; lowerrows++, k--)
{
for(int stars3=0; lowerrows>stars3-2; stars3++)
cout<<"*";
for(int j=0; j<height+k-3; j++)
{
if(lowerrows<j)
cout << " ";
}
for(int stars3=0; lowerrows>stars3-2; stars3++)
cout<<"*";
cout<<endl;
}
}



Output:


Hollow_Diamond_Shapes_In_C



0 comments:

Post a Comment