Update: I wrote this post back in 2009. I don’t maintain this blog anymore. Since there are lots of people still visiting this post and asking questions, I thought it would be a good idea to rewrite it. So I moved this post here. I have also added some brief explanation and some new shape using asterisks.
Please visit here for updated post. 🙂
It is a very common question for both C and C++ programmers that printing a diamond shape using asterisks (*) and this question is asked in almost every freaking semester 😉 .There are a lot of different ways to do that. But among them I found this one easier. Those who likes to use C code for printing diamond just change the header #include to #include, cout to printf and cin to scanf.Lets start the fun :)-
#include<iostream> #include<cstdlib> using namespace std; int main() { int i=0, j=0, NUM=3; for(i=-NUM; i<=NUM; i++) { for(j=-NUM; j<=NUM; j++) { if( abs(i)+abs(j)<=NUM) // Change this condition { cout<<"*"; } else { cout<<" ";} } cout<<endl; } return 0; }
The above code will prints-
*
***
*****
*******
*****
***
*
Wait what if you only need the outer shape of the diamond?Just change the ‘ if ‘ condition. You will get new design :). Wanna see???. Lets take a look-
if( abs(i)+abs(j)==NUM)
prints-
*
* *
* *
* *
* *
* *
*
if( abs(i)==abs(j))
prints-
* *
* *
* *
*
* *
* *
* *
if( abs(i)>=abs(j))
prints-
*******
*****
***
*
***
*****
*******
That’s it. Just change the condition and have fun with it. ENJOY 🙂
Please click here for how to print other shapes using asteriks.
is it possible to change the ‘if’ condition and create an oval shape?
***
* *
* *
* *
* *
***
dear this is not an oval shape ,please rectify your question.
i use microsoft visual studio 6 edition ,help me in writing program for printing diamond the above program is tough for me i didn’t know the “abs “
so simple. you can do this. please effort.
Sorry for late reply. 🙂 I had exm.
Yes it is possible to change the if condition and create an oval shape.
Look-In my code the for loop – “for(i=-NUM; i<=NUM; i++)" creates an 6×6 matrix and my "if" condition tells the compilers where to put the STARS and where to put the BLANK SPACE. You need to calculate where do you want to put your stars and change the "if" condition according to it 🙂 Simple isn't it?? 😀
hey i want to print for
____*
___*_*
__*_*_*
_*_*_*_*
__*_*_*
___*_*
____*
num=4…..may be on user input……
#include
#include
main()
{
int rows = 10;
for (int a = 1; a <= rows; a++){
for (int b = 1; b <= rows – a; b++)
printf("_");
for (int c = 1; c 0; e–){
for (int d = 1; d <= rows – e; d++)
printf("_");
for (int f = 1; f <= 2 * e – 1; f++)
printf("*");
printf("\n");
}
getch();
}
By;
#include
using namespace std;
int main()
{ int input,counter1=1,counter2=1,base=0,laststar=1,spaces1=0,spaces2=0,spaces3=0,numb=0,num1=1,num2=1,num3=1,num4=1,num5=1,num6=-1,num7=1,num8=0;
cout<>input;
spaces1=spaces2=(input-1)/2;
spaces3=spaces1+1;
base=spaces3+spaces1-2;
num8=base-2;
for(counter1=1;counter1<=spaces2;counter1++)
{
for(num1=1;num1<=spaces1;num1++)
{cout<<"-";}
cout<<"*";
if(num4!=counter1)
for(num5=1;num5<=num6;num5++)
cout<<"-";
if(num4!=counter1)
cout<<"*";
spaces1–;
num6=num6+2;
cout<<endl;
}
cout<<"*";
for(numb=1;numb<=base;numb++)
cout<<"-";
cout<<"*\n";
for(counter2=1;counter2<=spaces2;counter2++)
{ for(num2=1;num2<=num3;num2++)
cout<<"-";
cout<<"*";
if(num3==spaces3)
system("pause");
for(num7=1;num7<=num8;num7++)
cout<<"-";
if(laststar!=spaces2)
cout<<"*";
num3++;
num8=num8-2;
laststar++;
cout<<endl;
}
system("pause");
}
#include
using namespace std;
int main ()
{
int x,y,z,a,b,c;
x=1;
while (xx)
{
cout<<" ";
y–;
}
z=1;
while (z<=x)
{
cout<<"x";
cout<<" ";
z++;
}
cout<=1)
{
b=4;
while (b>a)
{
cout<<" ";
b–;
}
c=1;
while (c<=a)
{
cout<<" ";
cout<<"x";
c++;
}
cout<<endl;
a–;
}
return 0;
}
if you have got any answer of your question plz help me i have same problem
can we make this programs in two loops like this without using any built in function
as i am just a beginner in c++ so i couldn’t understand the iteration of your inner loop and outer loop and how your IF condition works. pleas..!! can you explain it will help me a lot to
thank you Sir for the diamond shape.But i didn’t understand the whole matter.Actually the steps i didn’t get that all…
Sir,i know this is difficult to make some one understood every line but Sir please do this for me.
thank you 🙂
the program for daimond shape you write have problem plz help me
“a prototype for abs” are shown as error
Hai Can you tell me how to print the stats in right angled triangle shape?
*
**
***
****
*****
i want to print the stars in the above shape, is it possible, please help me.
Yes! it is possible. You need to change the for loops-
for(i=-NUM; i<=0; i++)
and
for(j=0; j<=NUM; j++)
This will do it 🙂
why do u write negative sign before NUM ??
i didn’t get it yet
with out using the for loops
you can print the triangle using a simple “cout” statements
for example
int main()
{
cout<<"*\n";
cout<<"**\n";
cout<<"***\n";
cout<<"****\n";
cout<<"*****\n";
return 0;
}
#include
int main()
{
for(int i=1;i<6;i++)
{
for(int j=1;j<=i;j++)
{
printf("*");
}
printf(" \n");
}
return 0;
}
I think this is the way…….
no you r wrong…………………….]
for(int i=0;i<5;i++){
for(int j=0;j<i;j++){
printf("*");
}
printf("\n");
}
I think it is corhrect.
this is a program in which u can make triangle by choosing any suitable length:)
#include
#include “conio.h”
using namespace std;
void main()
{
int a=0;
cout<>a;
int b=1;
for (int i=1; i<=a; i++)
{
for (int j=1; j<=b; j++)
{
cout<<"*";
}
b++;
cout<<endl;
}
getch();
}
this is a program in which u can make triangle by choosing any suitable length:)
#include
#include “conio.h”
using namespace std;
void main()
{
int a=0;
cout<>a;
int b=1;
for (int i=1; i<=a; i++)
{
for (int j=1; j<=b; j++)
{
cout<<"*";
}
b++;
cout<<endl;
}
getch();
}
main()
{
for (int x=1;x<=5;x++)
{
for( int y=1;y<x;y++)
{
cout<<"*";
}
cout<<"\n";
}
getch();
}
int i,,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
cout<<"*";
}
cout<<endl;
}
getch();
}
this will give u d result
#include
#include
void main()
{
int n=5,i;
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
getch();
}
# include
using namespace std ;
void main()
{
int a = 1 , i = 1 ;
int height ;
cout <> height ;
while (a <= height)
{
while (i <=a)
{
cout << "*" ;
i++ ;
}
i = 1 ;
cout << endl ;
a++ ;
}
}
can anyone tell me how to print alphabets in increasing order in shape of B and X
just use for loop and print this 🙂
#include
int main
{
for(int i=1;i<=5;i++)
{
for(int j=1;j<=i;j++)
{
cout<<'*';
}
cout<<endl;
}
return 0;
}
in the above code if v not use stdlib and simply give the condition in if as if(i+j<=num).then this program remains correct?
Nope 🙂 It won’t !
rely it is you can compile and run it
ok thx.i hve did this n foud how it is incorrect.bt i hve also a question that without using the if statement in nested for how will the diamond print?
Upsss! Sorry But I didn’t get it. What did u wanna do?? did u want to print the diamond shape without using loop? or you wanna use another method to print diamond?? If you wanna use another method you may use array. 🙂
she means use nested for loops, not nested if
Is there a simpler way of doing it without using the “abs(i)”? I don’t understand how “abs(i)” works in the first place. (I’m a beginner)
Ya! there are other ways. But they will make the code longer. ‘abs’ tells the compiler to take only the absolute value of “i” form the for loop . 🙂 You can use array to make this Diamond shape. Take a look – Here
try using fabs under #include
Great solution! I just ran across this problem in Deitel’s & Deitel’s C++ book.
if i want it to not print but stick it into an 2d array… how do i do it?
ive tried changing the cout<<… to screen[i][j]='*'….
in short i need to get the diamond into a 2d array instead of printing… any solutions?
#include
#include
using namespace std;
int main()
{
int i=0, j=0, NUM=3;
char array [7][7];
for(i=-NUM; i<=NUM; i++)
{
for(j=-NUM; j<=NUM;)
{
if(abs(i)+abs(j)<=NUM)
{
array [3 + i][3 + j] = '*';
j++;
}
else
{
array [3 + i][3 + j] = ' ';
j++;
}
}
}
Print the array
for(i=0; i<=6; i++)
{
for(j=0; j<=6;)
{
if(abs(i)+abs(j)<=NUM)
{
cout << array [i][j];
j++;
}
else
{
cout << array [i][j];
j++;
}
}
cout << endl;
}
return 0;
}
i want to print like this using C++ simple tools please help me as fast as u can…..
****** ******
***** *****
**** ****
*** ***
** **
* *
it is wrong code, plz correct it
#include
void main ()
{
int a,b,c;
for(a=1;a<=6;a++)
{
for(b=1;b<=a;b++)
cout<<"*";
cout<<" ";
for(c=1;c<=a;c++)
cout<<"*";
cout<<endl;
}
}
******* ********
****** *******
****** *******
***** ******
**** *****
*** ***
** **
* *
using C++ for loops
#include
using namespace std;
int main()
{ int input,counter1=1,counter2=1,base=0,laststar=1,spaces1=0,spaces2=0,spaces3=0,numb=0,num1=1,num2=1,num3=1,num4=1,num5=1,num6=-1,num7=1,num8=0;
coutinput;
spaces1=spaces2=(input-1)/2;
spaces3=spaces1+1;
base=spaces3+spaces1-2;
num8=base-2;
for(counter1=1;counter1<=spaces2;counter1++)
{
for(num1=1;num1<=spaces1;num1++)
{cout<<"-";}
cout<<"*";
if(num4!=counter1)
for(num5=1;num5<=num6;num5++)
cout<<"-";
if(num4!=counter1)
cout<<"*";
spaces1–;
num6=num6+2;
cout<<endl;
}
cout<<"*";
for(numb=1;numb<=base;numb++)
cout<<"-";
cout<<"*\n";
for(counter2=1;counter2<=spaces2;counter2++)
{ for(num2=1;num2<=num3;num2++)
cout<<"-";
cout<<"*";
if(num3==spaces3)
system("pause");
for(num7=1;num7<=num8;num7++)
cout<<"-";
if(laststar!=spaces2)
cout<<"*";
num3++;
num8=num8-2;
laststar++;
cout<<endl;
}
system("pause");
}
opposite triangles of asterisk …. ascending and other descending
****** ********
***** *******
**** *****
** **
* *
someting like that
what’s the use of “abs”?
abs is used for the absolute values of “i” and “j” 🙂
Hai..i want to print like this using C..please help me as fast as u can…..
*********
* *
* *
* *
*********
thanx..
#include
void main(){
int height=4;
int m=height-2;
int width=10;
for(int i=0;i<width;i++){
printf("*");
}
printf("\n");
for(int e=0;e<m;e++){
printf("*");
printf("*");
printf("\n");
}
for(int c=0;c<width;c++)
printf("*");
scanf("%d",&width);
}
#include
void main()
{
int a,b,c;
for(a=1;a<=5;a++)
{
if(a==1)
{
for(b=1;b<=9;b++)
cout<<"x";
cout<<endl;
}
if((a!=1)&&(a!=5))
cout<<"**";
if (a==5)
{
for(c=1;c<=9;c++)
cout<<"x";
cout<<endl;
}
}
}
I program with c++ on Microsoft Visual Studio and I need to know a program that asks the user to enter two numbers, obtains the two numbers from the user and prints the sum, product, difference, and quotient of the two numbers.
#include
void main(){
int a,b;
printf(“Enter a and b \n”);
scanf(“%d%d”,&a,&b);
int sum=a+b;
int prod=a*b;
int dif=a-b;
int quo=a%b;
printf(“The sum of the two numbers is: %d\n”,sum);
printf(“The product of the two numbers is: %d\n”,prod);
printf(“The difference of the two numbers is: %d\n”,dif);
printf(“The quotient of the two numbers is: %d\n”,quo);
}
hi,,,em sanav… can any 1 help me in file handling…
Dear Dayeen,
Reely thanx for your above codes…..It helped me a lot…:)
can u generate a triangle lik dis??? kindly rply…:)
*
* *
* * *
* * * *
* * * * *
Thanx in advance:):)
# include
#include
void main()
{
clrscr();
for (int r=1; r<=5; r++)
{
for (int c=1; c<=r; c++)
cout<<"*";
cout<<endl<<endl;
}
getch();
}
i think this is right
its not running
#include
void main(){
for(int i=1; i<=5 ; i++){
for(int j=1;j<=i;j++){
cout<<"*";
}
cout<<endl;
}
}
Sorry…the above pattern is nt d one i needed….
first i wanna print space followed by single asterisk, then d astrerisk space n one more asterisk….hope u got ma query………:):)
#include
#include
void main()
{
clrscr();
{
for(int i=1;i<6;i++)
{
for(int j=1;j<=i;j++)
{
cout<<("*");
cout<<" ";
}
cout<<(" \n");
}
getch();;
}}
Can anyone please help me on how to explain these codes? Next week is our examination, and this is what I am going to present. Haha
Btw, thank you for this code. 🙂
program to print a diamond shape using a string.
like if i give ram then out put should be
a
r a m
a
if i give 12345
3
234
12345
234
3
hunh! easy…!
i need a code to print (the outline of diamond only) without {abs}funcion
in{if( abs(i)+abs(j)==NUM)}
(without using #include )
please quickly reply I need it before 9/4/2011
hey!
this stuff d’nt run in TURBO C++
unusual figure is seen while running above procedure …
How can i do this in TURBO c++ using abs()
plz
Help me!!!!
Reaally very simple and best solutions. Thanks buddy
thanks alot..gr8 help 4 begginners!
Nice work man.
hi please tell me how to print
1
13
135
1357
hi please tell me how to print
1
13
135
1357
hiii i need c code to print this pattern ..plz help me…
print S shape by using star
hi! can u please guide me to make a small game in c++.if u have any sourcecode or helping material related to this than please tell me.
*
**
***
**
*
Anyone give me the full right program of this?…………
#include
using namespace std;
void main()
{
int i=0,j=0,num=2;
for (i=-num;i<=num;i++)
{
for (j=0;j<=num;j++)
if (abs(i)+abs(j)<=num)
cout<<"*";
else
cout<<" ";
cout<<endl;
}}
how if i want to change it in number. from 1 to 36 in diamond shape.
please someone
#include
#include
#include
using namespace std;
int main()
{
char c =’*’;
int n;
for(n=0;n<5;n++)
{
if(n==0)
cout<<setw(4)<<c;
if(n==1)
cout<<setw(3)<<c<<c<<c;
if(n==2)
cout<<setw(2)<<c<<c<<c<<c<<c;
if(n==3)
cout<<setw(3)<<c<<c<<c;
if(n==4)
cout<<setw(4)<<c;
cout<<endl;
}
getch();
}
plz can anyone tell me how to make this shape plzzz
$$$$$$$$$$
$$$$ $$$$
$$$ $$$
$$ $$
$ $
$ $
$$ $$
$$$ $$$
$$$$ $$$$
$$$$$$$$$$
#include
using namespace std;
void main()
{
int i=0,j=0,num=6;
for (i=0;i<=num;i++)
{
for (j=0;j<=num;j++)
if (abs(i)+abs(j)<=num)
cout<<"*";
else
cout<<" ";
cout<<endl;
}
for (i=-num;i<=0;i++)
{
for (j=0;j<=num;j++)
if (abs(i)+abs(j)<=num)
cout<<"*";
else
cout<<" ";
cout<<endl;
}}
how can I print the given shape using for loops or while loops ?? Please help me out
************
***** *****
**** ****
*** ***
** **
* *
Can you tell me how can i make a diamond using while or for loop simply ?
Hi, I do not know how to print an inverted right angled triangle in C++ which will look as follows;
*
* *
* * *
* * * *
Can someone please help me?
( actually i am a begginner)
#include
using namespace std;
void main()
{
int i=0,j=0,num=5;
for (i=-num;i<=0;i++)
{
for (j=0;j<=num;j++)
if (abs(i)+abs(j)<=num)
cout<<"*";
else
cout<<" ";
cout<<endl;
}
}
#include
#include
int main()
{
for(int i=1; i<=4; i++)
{
for(int j=1; j<=i; j++)
cout<<"*";
cout<<endl<<endl;
}
getch();
}
how can you do this but make the user input a number to tell it how big it is.
if
the user types in 5, we would generate the following pattern:
*
* *
* *
* *
*
How could you do this shape?
if the user inputs 5 it would look like this:
*******
*** ***
** **
* *
** **
*** ***
*******
#include
using namespace std;
void main()
{
int i=0,j=0,num=6;
for (i=0;i<=num;i++)
{
for (j=0;j<=num;j++)
if (abs(i)+abs(j)<=num)
cout<<"*";
else
cout<<" ";
cout<<endl;
}
for (i=-num;i<=0;i++)
{
for (j=0;j<=num;j++)
if (abs(i)+abs(j)<=num)
cout<<"*";
else
cout<<" ";
cout<<endl;
}}
thanku soo much as it is very useful 🙂
goooooooooooooooooooood job i learn alot of this cods
thanks gues
#include
#include
main()
{
for(int i=1; i<=10;i++)
{for(int k=1; k=i)
cout<<"*";
cout<<endl;}
for(int j=1; j<=10;j++)
{for(int l=1; l=l)
cout<<"*";
cout<<endl;}
getch();
}
i am not able to understand this shape can u tell me one by one
int i=0, j=0, NUM=10;
for(i=-NUM; i<=NUM; i++)
{
for(j=-NUM; j<=NUM; j++)
{
//if( abs(i)+abs(j)<=NUM) // Change this condition
if( abs(i)+abs(j)==NUM)
{ cout<<"*"; }
else { cout<<" ";}
}
thanks
plz give me this problems codes
1)….1
…12
..123
.1234
12345
2)
*
**
***
**
*
hey there man….my asssignment requires the code to be purely C++ so plz help me out vid the if statement u used in the program…can the if statemet i-e if( abs(i)+abs(j)==NUM) be writen as if(i+j==NUM) if not then vat is the replacment?? and i dint understand the for loop u used the “i=-NUM” part…
am using only iostream.h header file as required by the asmnt..plz help me out….
if( abs(i)^abs(j))…It prints:-
Write a function printTriangle that prints out the letters of a given
string in a right triangle, as shown below. The first letter of the word appears once in the
first row, the second letter appears twice in the second row, and so on. Each column of
the triangle should have width 5. You may use the library. An example call
to the function is shown below, with the corresponding output
F
R R
O O O
D D D D
O O O O O
plz help me out
give coding in java to print
0
1 2
3 4 5
6 7 8 9
#include
#include
void main()
{
int i,j,old;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
old=j;
printf("%d",old);
old++;
}
printf("\n");
}
getch();
}
i need
*
*c*
**c**
*c*
*
how about this output what is the code for this output?* *
* *
* *
* * * * *
* * * * *
hahahaha,,jammo kanyam black merret..
can any one supply me the code of pattern
1
2 3
4 5 6
7 8 9 10
it is a good explanation!
#include
int main()
{
int i,j;
for(i=1;i<=4)
{
for(j=1;j<=i;j++)
cout<<j;
}
return 0;
}
a
b c
d e f
g h i j
please help me in printing a pyramid of alphabets
how to make a program in this output
1*
2**
3***
4****
5*****
#include
#include
int main()
{
for(int i=1; i<=5; i++)
{
cout<<i;
for(int j=1; j<=i; j++)
cout<<"*";
cout<<endl<<endl;
}
getch();
}
awesome
*
* * *
* * * * *
* * *
* * *
* * *
Can you tell me how can i make a shape like this using for loop simply ?
i wanna to print diamond shape using Two For Loop.help me plzzzzz 😦
* * * * *
* * * *
* *
* * * *
* * * * *
How can I make this shape using for-loop(C++)
Please help me. Thank you in advance. 🙂
It should be a diamond hole in a box. =)
999999999
88888888
7777777
666666
55555
4444
333
22
1
Could u tell me how to print this using a for loop ?
#include
#include
int main()
{
for(int i=9; i>=1; i–)
{
for(int j=1; j<=i; j++)
cout<<i;
cout<<endl<<endl;
}
getch();
}
how can we print a diamond of this figure
**********
*
*
*
*
*
*
*
*
*
*
* * * * * * * * *
* * * * * * * *
* * * * * *
* * * *
* *
* * * *
* * * * * *
* * * * * * * * *
please tell me for this code?
#include
using namespace std;
void main()
{
int i=0,j=0,num=2;
for (i=0;i<=num;i++)
{
for (j=0;j<=num;j++)
if (abs(i)+abs(j)<=num)
cout<<"*";
else
cout<<" ";
cout<<endl;
}
for (i=-num;i<=0;i++)
{
for (j=0;j<=num;j++)
if (abs(i)+abs(j)<=num)
cout<<"*";
else
cout<<" ";
cout<<endl;
}
}
#include
#include
using namespace std;
int main()
{
int i=0, j=0, NUM=3;
for(i=-NUM; i<=NUM; i++)
{
for(j=-NUM; j<=NUM; j++)
{
if( abs(i)+abs(j)<=NUM) // Change this condition
{ cout<<"*"; }
else { cout<<" ";}
}
cout<<endl;
}
return 0;
}
ano po ibig sabihin nung abs ???
Can someone help me with printing this shape please
********** **** **********
******** ******** ********
****** ************ ******
**** **************** ****
** ******************** **
** ******************** **
**** **************** ****
****** ************ ******
******** ******** ********
********** **** **********
use this one
1-if( abs(i)==abs(j))
replace * with space and space with staric in code
I need to print 3 simple pictures based on the number entered by the user
lets say the user enters 5
1st
&&&&&
&&&&&
&&&&&
&&&&&
&&&&&
2nd
&&&&&
&&&&
&&&
&&
&
3rd
&
&&&
&&&&&
&&&
&
thanks for helping me
Can someone help me with printing this shape please
*
***
*****
*
*
*
*
*
*
man i want to draw a heart using cout <<"\n any 1 can help
hello everyone plz i have an assignment..n i have to submit this assignment on coming monday……can anyone tell me the exact logic of this program using c lanuage
*
**
***
****
*****
******
*******
********
*********
********
*******
******
*****
****
***
**
*
I think this will be helpful for u.
#include
#include
int main()
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j=1;i–)
{
for(j=5;j>=i;j–)
{
printf(“*”,j);
}
printf(“\n”,i);
}
getch();
return 0;
}
#include
void main(){
int n,s,k,f=1,u;
cout<>n;
s=(n*2)-1;
k=s/2+1;
for(int i=1; i<=s; i++){
if(i<=k){
for(int j=1; j<=n;j++){
if(j<=i)
cout<<"*";
}
cout<<endl;
}
else
{ u=n-f;
for(int d=1;d<=n;d++){
if(d<=u)
cout<<"*";
}
f=f+1;
cout<<endl;
}
}
}
it is help full site i like it. KEEP IT UP!
#include
#include
int main()
{
int row,ast,space;
for (row=1;row<=5;row++)
{
for (space=1;space=row;ast–)
{
printf(“*”,ast);
}
printf(“\n”,row);
}
return 0;
}
*****
****
***
**
*
*
**
***
****
*****
thankw for your help
*****
_****
__***
___**
____*
____*
___**
__***
_****
*****
A B C D E F G F E D C B A
A B C D E F F E D C B A
A B C D E E D C B A
A B C D D C B A
A B C C B A
A B B A
A A
just i want to print upper alphabets so can u help me….?please send the code in my id…
help!
*
* *
* * * * *
* * * *
* * * * *
* *
*
sorry. here is it, i need this to display this 6 point star asterisks and i don’t know how to do in just a simple c++ code.
help please. i’m just a beginner.
____*
___*_*
_*_*_*_*_*
__*_*_*_*
_*_*_*_*_*
___*_*
____*
how to make
* *
** **
*** ***
********
{
int no-stars=1;
for(int i=0;i<10;i++) // your want
{
for(int j=0;j<i;j++)
cout<<"*";
no-stars+=2;
cout<<endl;
}
getche();
return 0;
}
i want liter K by stars
Thanks Good job.It was just what i needed.
i want explanation.Can u pls explain me this program.Why u used abs();
why u used abs in above program???
“thank u sir”
print the kite shape and user enter the num like i’m enter the 5 so only for 5 line print on output screen
Actually I meant like this
_______*
_____+___+
____*______*
___+++++++++
thanks so much sir i have an question if we not use abs to how possible make a diamond shape if its possible then tell me code
#include
#include
#include
int main()
{
clrscr();
int a, b, c, d;
cout<>c;
d=c;
for(a=0; a<=c; a++)
{
cout<<"\t\t";
cout<<setw(d+2);
d–;
for(b=0; b<=a; b++)
{
cout<<"*";
cout<<" ";
}
cout<=0; a–)
{
cout<<"\t\t";
cout<=1; b–)
{
cout<<"*";
cout<<" ";
}
cout<<endl;
}
getch();
return 0;
}
#include
#include
#include
int main()
{
clrscr();
int a, b, c, d;
cout<>c;
d=c;
for(a=0; a<=c; a++)
{
cout<<"\t\t";
cout<<setw(d+2);
d–;
for(b=0; b<=a; b++)
{
cout<<" *";
}
cout<=0; a–)
{
cout<<"\t\t";
cout<=1; b–)
{
cout<<" *";
}
cout<<endl;
}
getch();
return 0;
}
how to make this using for loop.
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*
Please check my new post here http://www.frdayeen.com/2016/10/how-to-print-shapes-using-asterisks-in-c-plus-plus-code.html for the answer.
this is awesome
Hi if i give n value 5 then it should be
*
***
*****
***
*
Please hlp me
Check this link for updated post- http://www.frdayeen.com/2016/10/how-to-print-shapes-using-asterisks-in-c-plus-plus-code.html
plz i want to print diamond from for and while loop and in which the for is for rows and while is for c can you do this
i want a program using do while loop for this shape:
*
**
***
****
*****
******
in dev-c++ syntax….
It has been discussed in updated post here: http://www.frdayeen.com/2016/10/how-to-print-shapes-using-asterisks-in-c-plus-plus-code.html. Please check. Thank you.
thank yooooooooooooou
what’s the logic this?
abc??????????
and using (-) with the name of variable???????????
How to make this using for/while in c++?
*
**
***
****
*****
****
***
**
*