write a programming using for loop in c++ to generate diamond
trangel?
Answer Posted / binoy
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 |
Post New Answer View All Answers
What is extern c++?
What do you mean by overhead in c++?
What is an orthogonal base class in c++?
Difference between Abstraction and encapsulation in C++?
what are the characteristics of Class Members in C++?
How do I tokenize a string in c++?
What is one dimensional array in c++?
How can you quickly find the number of elements stored in a dynamic array?
Explain the difference between using macro and inline functions?
When does a name clash occur in c++?
Do you know what is overriding?
Difference between a homogeneous and a heterogeneous container
What is the purpose of templates in c++?
What is the meaning of c++?
What type of question are asked in GE code writing test based on c++ data structures and pointers?