Thursday, January 22, 2015

c++ Creating Diamond Shape

Here is the code on how to crate diamond share in c++.

#include "stdafx.h"
#include<iostream>
using namespace std;
int main() {

int a, b, c;
    int n = 0;
    cout<<"Enter N:";
    cin>>n;

    for (a = 1; a <= n; a++)
    {
          for (b = 0; b < (n - a); b++)
                cout<<" ";
          for (b = 1; b <= a; b++)
                cout<<"*";
          for (c = 1; c < a; c++)
               cout<<"*";
cout<<"\n";
    }

    for (a = n - 1; a >= 1; a--)
    {
          for (b = 0; b < (n - a); b++)
               cout<<" ";
          for (b = 1; b <= a; b++)
                cout<<"*";
          for (c = 1; c < a; c++)
               cout<<"*";
         cout<<"\n";
    }
 
   cout<<"\n";


cin.get();
cin.get();
return 0;
}




No comments:

Post a Comment

Designed By Seo Blogger Templates Published.. Blogger Templates