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 stack unwinding.

0 Answers  


What is basic if statement syntax?

0 Answers  


Write syntax to define friend functions in C++.

0 Answers   HAL,


How to give an alternate name to a namespace?

0 Answers  


What is endl?

0 Answers  






What gives the current position of the put pointer?

0 Answers  


What is c++ code?

0 Answers  


What is the latest c++ version?

0 Answers  


why we cant create array of refrences

4 Answers  


Why do we use iterators?

0 Answers  


Can member functions be private?

0 Answers  


Why can templates only be implemented in the header file?

0 Answers  


Categories