write a programming using for loop in c++ to generate diamond
trangel?



write a programming using for loop in c++ to generate diamond trangel?..

Answer / 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

More C++ General Interview Questions

What are the different types of polymorphism in c++?

0 Answers  


Does a derived class inherit or doesn't inherit?

0 Answers  


Are c and c++ different?

0 Answers  


How do you flush a buffer in c++?

0 Answers  


What is the c++ code?

0 Answers  






print first nodd numbers in descending order

7 Answers  


What is isdigit c++?

0 Answers  


What are smart pointers?

0 Answers  


Can a constructor be private?

0 Answers  


what are prototypes

4 Answers   Infosys, TCS,


What is the difference between map and hashmap in c++?

0 Answers  


How do you generate a random number in c++?

0 Answers  


Categories