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

Show the declaration for a static function pointer.

1024


What is a tree in c++?

928


What are built-in functions? What is the syntax for the definition?

1042


Can you please explain the difference between static and dynamic binding of functions?

989


Why do we use using namespace std in c++?

1039


What are the different types of comments allowed in c++?

941


What is virtual base class?

1028


total amount of milk produced each morning and then calculates and outputs the number of cartons needed for this milk , the cost of producing the milk and the profit from producing this milk.

2540


What language does google use?

1102


What is the difference between public, private, and protected access?

1026


What is vector pair in c++?

1187


What are virtual constructors/destructors?

961


What is the difference between a declaration and a definition?

1059


Give the difference between the type casting and automatic type conversion. Also tell a suitable C++ code to illustrate both.

1007


What is the use of string in c++?

990