write a programming using for loop in c++ to generate diamond
trangel?
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 |
What can I use instead of namespace std?
What jobs can you get with a c++ certification?
What is an explicit constructor?
What is the difference between method and message?
What are the different types of polymorphism in c++?
What is a static element?
what is Loop function? What are different types of Loops?
what you know about c++?
What is a pointer how and when is it used?
How to write a program such that it will delete itself after exectution?
Is sorted c++?
Can user-defined object be declared as static data member of another class?