write a programming using for loop in c++ to generate diamond
trangel?
Answer Posted / 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 View All Answers
Show the declaration for a static function pointer.
What is a tree in c++?
What are built-in functions? What is the syntax for the definition?
Can you please explain the difference between static and dynamic binding of functions?
Why do we use using namespace std in c++?
What are the different types of comments allowed in c++?
What is virtual base class?
total amount of milk produced each morning and then calculates and outputs the number of cartons needed for this milk , the cost of producing the milk and the profit from producing this milk.
What language does google use?
What is the difference between public, private, and protected access?
What is vector pair in c++?
What are virtual constructors/destructors?
What is the difference between a declaration and a definition?
Give the difference between the type casting and automatic type conversion. Also tell a suitable C++ code to illustrate both.
What is the use of string in c++?