write a programming using for loop in c++ to generate diamond
trangel?
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();
}
Another solution for the same question :
http://programscpp.blogspot.in/2012/08/program-to-print-diamond-in-box-2.html
| Is This Answer Correct ? | 6 Yes | 2 No |
State the difference between pre and post increment/decrement operations.
why can't we declare data member of class auto register or extern
Can a constructor return a value?
How to implement flags?
plz send me National informatics center paper pattern
How to tokenize a string in c++?
What is a forward referencing and when should it be used?
What is the difference between #import and #include?
Describe delete operator?
What is an incomplete type in c++?
Is there any difference between dlearations int* x and int *x? If so tell me the difference?
How many bit combinations are there in a byte?