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 virtual functions in C++.

3 Answers  


What are the differences between new and malloc?

0 Answers  


Explain static and dynamic memory allocation with an example each.

0 Answers  


What is c++ flowchart?

0 Answers  


Explain virtual destructor?

0 Answers  


which is the easy way to divide any integer by 2?

2 Answers   Persistent,


Write a program to find the Fibonacci series recursively.

0 Answers   Huawei,


What are the types of container classes?

0 Answers  


Does there exist any way to make the command line arguments available to other functions without passing them as arguments to the function?

0 Answers  


What are the advantage of using register variables?

0 Answers  


What is implicit pointer in c++?

0 Answers  


What is data binding in c++?

0 Answers  


Categories