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 are the different types of polymorphism in c++?
Does a derived class inherit or doesn't inherit?
Are c and c++ different?
How do you flush a buffer in c++?
What is the c++ code?
print first nodd numbers in descending order
What is isdigit c++?
What are smart pointers?
Can a constructor be private?
what are prototypes
What is the difference between map and hashmap in c++?
How do you generate a random number in c++?