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 are the basic data types used in c++?

750


What is the use of structure in c++?

730


What is an html tag?

811


How do you master coding?

790


What is the use of data hiding?

765


Is facebook written in c++?

741


What is a c++ vector?

771


Does c++ support multilevel and multiple inheritances?

729


How we can differentiate between a pre and post increment operators during overloading?

819


Explain mutable storage class specifier.

823


Do the parentheses after the type name make a difference with new?

834


What are the rules about using an underscore in a c++ identifier?

819


What is pointer -to-members in C++? Give their syntax?

775


How do I tokenize a string in c++?

788


Which c++ compiler is best?

814