Pages

100 Contemporary Living Room Designs

Monday, August 13, 2012

PROGRAM TO PRINT A DIAMOND IN A BOX - 1

C++ program to print a diamond inside a box using asterisks.

#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
  int i=0,j=0,num;
  clrscr();
  cout<<"Enter limit\n";
  cin>>num;
  cout<<endl;
  for(i=-(num+2);i<=num+2;i++)
  {
    for(j=-(num+2);j<=num+2;j++)
    {
      if(abs(i)+abs(j)<=num||j==-(num+2)
      ||j==(num+2)||i==-(num+2)||i==(num+2))
      {
        cout<<"*";
      }
      else
      {
        cout<<" ";
      }
    }
    cout<<endl;
  }
  getch();
}

output

  You may also like:
   C++ program to print a diamond inside a box  using asterisks.
   















No comments:

Post a Comment