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


Please Help Members By Posting Answers For Below Questions

What is called array?

624


Write a program that takes a 5 digit number and calculates 2 power that number and prints it.

2073


How do you import payscale data from non SAP to SAP?is it through LSMW or any other way is there?

3206


Does a derived class inherit or doesn't inherit?

620


Is turbo c++ free?

627






What should main() return in c and c++?

530


Explain terminate() and unexpected() function?

630


What is c++ & why it is used?

592


What is function overloading in C++?

737


Explain the use of virtual destructor?

629


What is low level language in simple words?

566


How to access a variable of the structure?

585


What is c++ library?

598


write a function signature with various number of parameters.

569


What is the best c++ book?

714