Print a diamond shape using asterisks in C/C++

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.

This entry was posted in C/C++, programming and tagged , , . Bookmark the permalink.

162 Responses to Print a diamond shape using asterisks in C/C++

  1. Kyriacos says:

    is it possible to change the ‘if’ condition and create an oval shape?
    ***
    * *
    * *
    * *
    * *
    ***

  2. dayeen says:

    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?? 😀

    • shyam karthik says:

      hey i want to print for
      ____*
      ___*_*
      __*_*_*
      _*_*_*_*
      __*_*_*
      ___*_*
      ____*
      num=4…..may be on user input……

      • o2o82k12 says:

        #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();

        }

      • Programmer says:

        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");
        }

      • HEARTBREAKER says:

        #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;
        }

      • junaid khan says:

        if you have got any answer of your question plz help me i have same problem

    • zoraizshah says:

      can we make this programs in two loops like this without using any built in function

    • ahmed says:

      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

    • udoyjalal4 says:

      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 🙂

    • junaid khan says:

      the program for daimond shape you write have problem plz help me
      “a prototype for abs” are shown as error

  3. sheela says:

    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.

    • dayeen says:

      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 🙂

    • firstguest says:

      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;
      }

    • subhani says:

      #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…….

    • hussein says:

      for(int i=0;i<5;i++){
      for(int j=0;j<i;j++){
      printf("*");
      }
      printf("\n");
      }

    • Abdullah says:

      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();
      }

      • Abdullah says:

        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();
        }

    • dosage says:

      main()
      {
      for (int x=1;x<=5;x++)
      {
      for( int y=1;y<x;y++)
      {

      cout<<"*";
      }
      cout<<"\n";

      }

      getch();
      }

    • srabanti says:

      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

    • satyanarayana raju says:

      #include
      #include
      void main()
      {
      int n=5,i;
      for(i=1;i<=n;i++)
      {
      for(j=1;j<=i;j++)
      {
      printf("*");
      }
      printf("\n");
      }
      getch();
      }

    • Afnan Bhutta says:

      # 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++ ;
      }

      }

    • Hasnat Ahmad says:

      just use for loop and print this 🙂

    • yordanos getahun says:

      #include
      int main
      {
      for(int i=1;i<=5;i++)
      {
      for(int j=1;j<=i;j++)
      {
      cout<<'*';
      }
      cout<<endl;
      }
      return 0;
      }

  4. eman ali says:

    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?

  5. eman ali says:

    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?

    • dayeen says:

      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. 🙂

  6. someone says:

    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)

  7. Chris C. says:

    Great solution! I just ran across this problem in Deitel’s & Deitel’s C++ book.

  8. jony says:

    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?

    • Array Man says:

      #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;
      }

  9. bscs2010gcu says:

    i want to print like this using C++ simple tools please help me as fast as u can…..
    ****** ******
    ***** *****
    **** ****
    *** ***
    ** **
    * *

  10. bscs2010gcu says:

    ******* ********
    ****** *******
    ****** *******
    ***** ******
    **** *****
    *** ***
    ** **
    * *
    using C++ for loops

    • Bunty says:

      #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");
      }

  11. bscs2010gcu says:

    opposite triangles of asterisk …. ascending and other descending

    ****** ********
    ***** *******
    **** *****
    ** **
    * *
    someting like that

  12. beaiya14 says:

    what’s the use of “abs”?

  13. nurul says:

    Hai..i want to print like this using C..please help me as fast as u can…..

    *********
    * *
    * *
    * *
    *********

    thanx..

    • hussein says:

      #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);
      }

    • abdullah says:

      #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;
      }
      }
      }

  14. Anisa Cochran says:

    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.

    • hussein says:

      #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);
      }

  15. satnav vishwakarma says:

    hi,,,em sanav… can any 1 help me in file handling…

  16. vikram says:

    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:):)

  17. vikram says:

    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………:):)

  18. aerastello says:

    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. 🙂

  19. Vibhor says:

    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

  20. khalaf says:

    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

  21. sanav says:

    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!!!!

  22. info says:

    Reaally very simple and best solutions. Thanks buddy

  23. Me says:

    thanks alot..gr8 help 4 begginners!

  24. Tameem Akhtar says:

    Nice work man.

  25. Muhammad oan says:

    hi please tell me how to print
    1
    13
    135
    1357

  26. hi please tell me how to print
    1
    13
    135
    1357

  27. sahithi says:

    hiii i need c code to print this pattern ..plz help me…

    print S shape by using star

  28. nabeel says:

    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.

  29. gcian1 says:

    *
    **
    ***
    **
    *
    Anyone give me the full right program of this?…………

    • arslaan says:

      #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;
      }}

  30. izafiza says:

    how if i want to change it in number. from 1 to 36 in diamond shape.

  31. izafiza says:

    please someone

  32. #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();
    }

  33. Attiq says:

    plz can anyone tell me how to make this shape plzzz

    $$$$$$$$$$
    $$$$ $$$$
    $$$ $$$
    $$ $$
    $ $
    $ $
    $$ $$
    $$$ $$$
    $$$$ $$$$
    $$$$$$$$$$

    • arslaan says:

      #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;
      }}

  34. aahmer says:

    how can I print the given shape using for loops or while loops ?? Please help me out

    ************
    ***** *****
    **** ****
    *** ***
    ** **
    * *

  35. yupi says:

    Can you tell me how can i make a diamond using while or for loop simply ?

  36. phoebs says:

    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)

  37. lah2ba says:

    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:
    *
    * *
    * *
    * *
    *

  38. Ace Egg says:

    How could you do this shape?
    if the user inputs 5 it would look like this:
    *******
    *** ***
    ** **
    * *
    ** **
    *** ***
    *******

    • arslaan says:

      #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;
      }}

  39. taha says:

    thanku soo much as it is very useful 🙂

  40. ibrahim mohamed says:

    goooooooooooooooooooood job i learn alot of this cods
    thanks gues

  41. this is a solution of Mr Atiq Question says:

    #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();
    }

  42. Salman says:

    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<<" ";}

    }

  43. john says:

    thanks

  44. radia says:

    plz give me this problems codes

    1)….1
    …12
    ..123
    .1234
    12345

    2)
    *
    **
    ***
    **
    *

  45. Sohaib Imran says:

    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….

  46. vishal & upinder says:

    if( abs(i)^abs(j))…It prints:-

  47. maham says:

    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

  48. DINOLD JEEVA C says:

    give coding in java to print
    0
    1 2
    3 4 5
    6 7 8 9

    • sharad soni says:

      #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();
      }

  49. RANJITH says:

    i need
    *
    *c*
    **c**
    *c*
    *

  50. lizza Valdez says:

    how about this output what is the code for this output?* *
    * *
    * *
    * * * * *
    * * * * *

  51. simhirin says:

    can any one supply me the code of pattern
    1
    2 3
    4 5 6
    7 8 9 10

  52. simhirin says:

    a
    b c
    d e f
    g h i j

  53. simhirin says:

    please help me in printing a pyramid of alphabets

  54. edwin says:

    how to make a program in this output
    1*
    2**
    3***
    4****
    5*****

  55. James says:

    *
    * * *
    * * * * *
    * * *
    * * *
    * * *
    Can you tell me how can i make a shape like this using for loop simply ?

  56. fawad says:

    i wanna to print diamond shape using Two For Loop.help me plzzzzz 😦

  57. KuroHime1507 says:

    * * * * *
    * * * *
    * *
    * * * *
    * * * * *

    How can I make this shape using for-loop(C++)
    Please help me. Thank you in advance. 🙂

  58. Sasha says:

    999999999
    88888888
    7777777
    666666
    55555
    4444
    333
    22
    1
    Could u tell me how to print this using a for loop ?

  59. ahmad khan says:

    how can we print a diamond of this figure
    **********
    *
    *
    *
    *
    *
    *
    *
    *
    *
    *

  60. yogi says:

    * * * * * * * * *
    * * * * * * * *
    * * * * * *
    * * * *
    * *
    * * * *
    * * * * * *
    * * * * * * * * *

    please tell me for this code?

    • arslaan says:

      #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;
      }
      }

  61. #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 ???

  62. Zakir Rahimi says:

    Can someone help me with printing this shape please

    ********** **** **********
    ******** ******** ********
    ****** ************ ******
    **** **************** ****
    ** ******************** **
    ** ******************** **
    **** **************** ****
    ****** ************ ******
    ******** ******** ********
    ********** **** **********

  63. Josue Guzman says:

    I need to print 3 simple pictures based on the number entered by the user
    lets say the user enters 5
    1st
    &&&&&
    &&&&&
    &&&&&
    &&&&&
    &&&&&

    2nd
    &&&&&
    &&&&
    &&&
    &&
    &
    3rd
    &
    &&&
    &&&&&
    &&&
    &

  64. ajwad says:

    thanks for helping me

  65. sara khan says:

    Can someone help me with printing this shape please
    *
    ***
    *****
    *
    *
    *
    *
    *
    *

  66. HMZ17 says:

    man i want to draw a heart using cout <<"\n any 1 can help

  67. areeba butt says:

    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
    *
    **
    ***
    ****
    *****
    ******
    *******
    ********
    *********
    ********
    *******
    ******
    *****
    ****
    ***
    **
    *

    • Muhammad Umair Abid says:

      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;
      }

    • nomi says:

      #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;
      }

      }
      }

  68. Magnaw says:

    it is help full site i like it. KEEP IT UP!

  69. Muhammad Umair Abid says:

    #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;
    }

  70. Brett says:

    *****
    ****
    ***
    **
    *

    *
    **
    ***
    ****
    *****

  71. Brett says:

    *****
    _****
    __***
    ___**
    ____*

    ____*
    ___**
    __***
    _****
    *****

  72. vinay kashyap says:

    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…

  73. ange says:

    help!

    *
    * *
    * * * * *
    * * * *
    * * * * *
    * *
    *

  74. ange says:

    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.

    ____*
    ___*_*
    _*_*_*_*_*
    __*_*_*_*
    _*_*_*_*_*
    ___*_*
    ____*

  75. shubham says:

    how to make
    * *
    ** **
    *** ***
    ********

    • shujaat ali says:

      {
      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;
      }

  76. rzgar says:

    i want liter K by stars

  77. Fahad says:

    Thanks Good job.It was just what i needed.

  78. rita says:

    i want explanation.Can u pls explain me this program.Why u used abs();

  79. maira says:

    why u used abs in above program???

  80. Hasrat Ali says:

    “thank u sir”

  81. sunil says:

    print the kite shape and user enter the num like i’m enter the 5 so only for 5 line print on output screen

  82. charanteja says:

    Actually I meant like this
    _______*
    _____+___+
    ____*______*
    ___+++++++++

  83. Hamza tabassum says:

    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

    • GAURAV SINGH says:

      #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;
      }

  84. Gaurav Singh says:

    #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;
    }

  85. aino says:

    how to make this using for loop.
    *
    * *
    * * *
    * * * *
    * * * * *
    * * * *
    * * *
    * *
    *

  86. pragadish says:

    Hi if i give n value 5 then it should be
    *
    ***
    *****
    ***
    *
    Please hlp me

  87. haseeb says:

    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

  88. mah says:

    i want a program using do while loop for this shape:
    *
    **
    ***
    ****
    *****
    ******
    in dev-c++ syntax….

  89. iram chohdary says:

    thank yooooooooooooou

  90. iram chohdary says:

    what’s the logic this?
    abc??????????
    and using (-) with the name of variable???????????

  91. Mr. Curious says:

    How to make this using for/while in c++?

    *
    **
    ***
    ****
    *****
    ****
    ***
    **
    *

Leave a reply to info Cancel reply