Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

How the delete operator differs from the delete[]operator?

1091


What is the difference between #define debug 0 and #undef debug?

1178


Which should be more useful: the protected and public virtuals?

1029


What is the use of cmath in c++?

1058


What can I use instead of namespace std?

1145


Are strings immutable in c++?

1146


What are the 4 types of library?

1173


Define friend function.

1039


how to connect with oracle 9i with server in socket program in c/c++

2338


Out of fgets() and gets() which function is safe to use?

1124


Should the member functions which are made public in the base class be hidden?

1028


What is different in C++, compare with unix?

1086


What is the difference between the parameter to a template and the parameter to a function?

1116


Is it possible to use a new for the reallocation of pointers ?

1047


What is pure virtual function? Or what is abstract class?

1051