Tuesday 13 August 2013

Hollow Diamond 1


Hollow Diamond 1:

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

Code:

Copy the code from here.
/*    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 length=0;

cout << "Enter the length of the hollow diamond\n";
cin>>length;

for(int i=0, k=length, l=length; i<length; i++, k++, l--)
{
for(int j=0; j<2*length; j++)
{
if(j==k || j==l)
cout << "*";
else
cout << " ";
}
cout<<endl;
}
for(int i=0, k=0, l=2*length; i<=length; i++, k++, l--)
{
for(int j=0; j<=2*length; j++)
{
if(j==k || j==l)
cout << "*";
else
cout << " ";
}
cout<<endl;
}


}

Output:



Hollow_Diamond_Shapes_In_C



1 comments: