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:




4 comments:

  1. Too many errors in these codes
    tell me which C++ client are you using
    Thank You

    ReplyDelete
    Replies
    1. At my side, it's perfectly running!!!
      Is there any logical error or compile time error??
      Please state your views ... we'll solve it and update you with it!!!
      Thanks for your concern!!!

      Delete
    2. Please upload the C++ compiler or give me the link to that compiler or give me name of that compiler so that I can try this
      I think that error is due to my compilers.There are different codes for different compilers.
      Thanks for your effort
      Appreciate your work
      keep them coming
      Thank You

      Delete
    3. Thank you dear...
      No problem ... wait for some hours ... I'll upload an article that how to run this code in your turbo C++ compiler ... And then you can run this code and enjoy it and yeah run that moving fan one too ... that one is amazing ...
      And this code works in Microsoft visual studio 2012 ... Use this compiler ... Turbo C++ is very old now and it is very difficult to use for people like us :)

      Delete