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
Assume an array of structure is in order by studentID field of the record, where student IDs go from 101 to 500. Write the most efficient pseudocode algorithm you can to find the record with a specific studentID if every single student ID from 101 to 500 is used and the array has 400 elements. Write the most efficient pseudocode algorithm you can to find a record with a studentID near the end of the IDs, say in the range from 450 to 500, if not every single student ID in the range of 101 to 500 is used and the array size is only 300
How much is c++ certification?
How does c++ structure differ from c++ class?
Is dev c++ a good compiler?
Should the this pointer can be used in the constructor?
How can you quickly find the number of elements stored in a static array?
Who created c++?
What is the output of the following program? Why?
What are references in c++? What is a local reference?
How c functions prevents rework and therefore saves the programers time as wel as length of the code ?
What do you mean by static variables?
How do you find out if a linked-list has an end?
How do you define a class in c++?
What is object in c++ wikipedia?
Explain the difference between overloading and overriding?