write a programming using for loop in c++ to generate diamond
trangel?
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 |
Explain function overloading and operator overloading.
Consider the following code fragment: int main(void) { int m = 4; mystery ( m ); mystery ( m ); printf("%d", m); return 0; } What is the output on the monitor if mystery is defined as follows ? void mystery (int m) { m = m+3; }
What is a binary file? List the merits and demerits of the binary file usagein C++.
What happens when the extern "c" char func (char*,waste) executes?
Which is the best c++ compiler?
What is function overloading c++?
How can you create a virtual copy constructor?
Which is the best c++ compiler for beginners?
What are c++ templates used for?
How to implement flags?
What is the importance of mutable keyword?
Write a program using merge () function to combine the elements of array x[ ] and y[ ] into array z[ ].