Showing posts with label Diamond. Show all posts
Showing posts with label Diamond. Show all posts

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



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



Monday, 12 August 2013

Diamond Code

Diamond:

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

Code:

copy your code from below:
/* 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";
int length=0;
cout << "Enter the size of the Diamond\n";
cin>>length;
for(int i=length, k=0; i>=0; i--, k++)
{
for(int j=0; j<length+k; j++)
{
if(j>i)
cout << "*";
else
cout << " ";
}
cout<<endl;
}
for(int i=1, k=length; i<length; i++, k--)
{
for(int j=0; j<length+k-1; j++)
{
if(i<j)
cout << "*";
else
cout << " ";
}
cout<<endl;
}
}

Output: