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 can I use instead of namespace std?

1 Answers  


What jobs can you get with a c++ certification?

1 Answers  


What is an explicit constructor?

1 Answers  


What is the difference between method and message?

5 Answers   HP,


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

1 Answers  


What is a static element?

1 Answers  


what is Loop function? What are different types of Loops?

1 Answers  


what you know about c++?

1 Answers   IBS,


What is a pointer how and when is it used?

1 Answers  


How to write a program such that it will delete itself after exectution?

3 Answers  


Is sorted c++?

1 Answers  


Can user-defined object be declared as static data member of another class?

1 Answers  


Categories