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
What is called array?
Write a program that takes a 5 digit number and calculates 2 power that number and prints it.
How do you import payscale data from non SAP to SAP?is it through LSMW or any other way is there?
Does a derived class inherit or doesn't inherit?
Is turbo c++ free?
What should main() return in c and c++?
Explain terminate() and unexpected() function?
What is c++ & why it is used?
What is function overloading in C++?
Explain the use of virtual destructor?
What is low level language in simple words?
How to access a variable of the structure?
What is c++ library?
write a function signature with various number of parameters.
What is the best c++ book?