Monday, September 30, 2019

C++ code Diamond shape of space

Code
#include <iostream>
using namespace std;

int main()
{
   int i,j,r;
    cout << " Input number of rows : ";
    cin >> r;
   for(i=1;i<r;i++)
   {
    for(j=0;j<=r-i;j++)
     cout<<"*";
     for(j=2;j<=2*i-1;j++)
    cout<<" ";
       for(j=0;j<=r-i;j++)
     cout<<"*";
     cout<<endl;
   }
   for(i=r-1;i>=1;i--)
   {
     for(j=0;j<=r-i;j++)
     cout<<"*";
     for(j=2;j<=2*i-1;j++)
    cout<<" ";
       for(j=0;j<=r-i;j++)
     cout<<"*";
     cout<<endl;
   }
   cout<<endl;
   return 0;
}

Output:

No comments:

Post a Comment

C++ BLACKJACK

#include <iostream> #include <ctime> #include <stdlib.h> #include <time.h> #include <string> using namesp...