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 |
What is prototype for that c string function?
Explain the use of this pointer?
Using a smart pointer can we iterate through a container?
Can a function take variable length arguments, if yes, how?
What does the ios::ate argument do?
int *p = NULL; printf("%1d",p) ; what will be the output of this above code?
What is the outcome of cout< a) 16 b) 17 c) 16.5
What are enumerations?
What are exceptions c++?
what is the difference between linear list linked representaion and linked representation? what is the purpose of representing the linear list in linked represention ? is it not avoiding rules of linear represention?
What is vector string in c++?
How to write a program such that it will delete itself after exectution?