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

Distinguish between a # include and #define.

754


describe private access specifiers?

747


Tell me difference between constant pointer and pointer to a constant.

746


What are the two types of comments?

663


Why do we use classes in c++?

679






What is struct c++?

649


Is c++ the most powerful language?

649


What is constructor c++?

767


Can c++ do everything c can?

695


How does c++ sort work?

647


What is static class data?

658


Differentiate between a pointer and a reference with respect to c++.

795


What is the best way to take screenshots of a window with c++ in windows?

668


Can class objects be passed as function arguments?

695


Which programming language is best?

649