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
Do we have to use initialization list in spite of the assignment in constructors?
What programming language should I learn first?
What are features of c++?
What happens when you make call 'delete this;'?
What are the defining traits of an object-oriented language?
What is the function to call to turn an ascii string into a long?
What is a dll entry point?
Define the process of handling in case of destructor failure?
What are the various oops concepts in c++?
What is conditions when using boolean operators?
What is the rule of three?
Why is "using namespace std;" considered bad practice?
What is dynamic and static typing?
What is the difference between an external iterator and an internal iterator? Describe an advantage of the external iterator.
When must you use a pointer rather than a reference?