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

Explain function overloading and operator overloading.

0 Answers  


Consider the following code fragment: int main(void) { int m = 4; mystery ( m ); mystery ( m ); printf("%d", m); return 0; } What is the output on the monitor if mystery is defined as follows ? void mystery (int m) { m = m+3; }

2 Answers   CDAC, Wipro,


What is a binary file? List the merits and demerits of the binary file usagein C++.

0 Answers  


What happens when the extern "c" char func (char*,waste) executes?

0 Answers  


Which is the best c++ compiler?

0 Answers  






What is function overloading c++?

0 Answers  


How can you create a virtual copy constructor?

0 Answers  


Which is the best c++ compiler for beginners?

0 Answers  


What are c++ templates used for?

0 Answers  


How to implement flags?

2 Answers   Symphony,


What is the importance of mutable keyword?

0 Answers  


Write a program using merge () function to combine the elements of array x[ ] and y[ ] into array z[ ].

0 Answers  


Categories