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
How the delete operator differs from the delete[]operator?
What is the difference between #define debug 0 and #undef debug?
Which should be more useful: the protected and public virtuals?
What is the use of cmath in c++?
What can I use instead of namespace std?
Are strings immutable in c++?
What are the 4 types of library?
Define friend function.
how to connect with oracle 9i with server in socket program in c/c++
Out of fgets() and gets() which function is safe to use?
Should the member functions which are made public in the base class be hidden?
What is different in C++, compare with unix?
What is the difference between the parameter to a template and the parameter to a function?
Is it possible to use a new for the reallocation of pointers ?
What is pure virtual function? Or what is abstract class?