10 Challenging star pattern programs in C

by Utsav Banerjee on October 19, 2009


star pattern screenshotComputer languages are not as easy as human languages, they need you to become a computer yourself, think like a computer and write an algorithm. Computer programs are fun if you take them up as a challenge, as unsolved puzzles. There is lot of fun in taking up the challenge, understanding the problem, writing an algorithm, writing a program and most importantly running the program and obtaining required output.

Here are few challenging C program questions for you. Let’s see how many of them you would be able to write without seeing the program solution given below. These questions are to print patterns using asterisk(star) character. Comment below if you have tougher pattern questions.

Also read Number Pattern Programs

  1. Write a C program to print the following pattern:
             *
          *  *
       *  *  *
    *  *  *  *
    
  2. Write a C program to print the following pattern:
    *                   *
    * * *           * * *
    * * * * *   * * * * *
    * * * * * * * * * * *
    
  3. Write a C program to print the following pattern:
    *                         *
       *                   *
    *     *             *     *
       *     *       *     *
    *     *      *      *     *
       *     *       *     *
    *     *             *     *
       *                   *
    *                         *
    
  4. Write a C program to print the following pattern:
    *   *   *   *   *
      *   *   *   *
        *   *   *
          *   *
            *
          *   *
        *   *   *
      *   *   *   *
    *   *   *   *   *
    
  5. Write a C program to print the following pattern:
              *
            * * *
          * * * * *
        * * * * * * *
      * * * * * * * * *
        * * * * * * *
          * * * * *
            * * *
              *
            * * *
          * * * * *
    
  6. Write a C program to print the following pattern:
         *
           * *
             * * *
               * * * *
             * * *
           * *
         *
    
  7. Write a C program to print the following pattern:
    * * * * * * * * *
    * * * *   * * * *
    * * *       * * *
    * *           * *
    *               *
    * *           * *
    * * *       * * *
    * * * *   * * * *
    * * * * * * * * *
    
  8. Write a C program to print the following pattern:
    * * * * * * * * * * * * * * * * *
      * * * * * * *   * * * * * * *
        * * * * *       * * * * *
          * * *           * * *
            * * * * * * * * *
              * * * * * * *
                * * * * *
                  * * *
                    *
    
  9. Write a C program to print the following pattern:
          *
        * * *
      * * * * *
    * * * * * * *
    *           *
    * *       * *
    * * *   * * *
    * * * * * * *
    * * *   * * *
    * *       * *
    *           *
    * * * * * * *
      * * * * *
        * * *
          *
    
  10. Write a C program to print the following pattern:
    * * * * * * * * * * * * * * * * * * * * * * * * *
      *           *   *           *   *           *
        *       *       *       *       *       *
          *   *           *   *           *   *
            *               *               *
          *   *           *   *           *   *
        *       *       *       *       *       *
      *           *   *           *   *           *
    * * * * * * * * * * * * * * * * * * * * * * * * *
    
     

  1. Write a C program to print the following pattern:
  2.          *
          *  *
       *  *  *
    *  *  *  *

    Program:

    /* This is a simple mirror-image of a right angle triangle */
    
    #include
    int main() {
     char prnt = '*';
     int i, j, nos = 4, s;
     for (i = 1; i <= 5; i++) { for (s = nos; s >= 1; s--) {  // Spacing factor
       printf("  ");
      }
      for (j = 1; j <= i; j++) {
       printf("%2c", prnt);
      }
      printf("\n");
      --nos;   // Controls the spacing factor
     }
     return 0;
    }

    Download Code

    Back to top

  3. Write C program to print the following pattern:
    *                   *
    * * *           * * *
    * * * * *   * * * * *
    * * * * * * * * * * *
  4. Program:

    #include
    int main() {
     char prnt = '*';
     int i, j, k, s, c = 1, nos = 9;
     for (i = 1; c <= 4; i++) {
         // As we want to print the columns in odd sequence viz. 1,3,5,.etc
      if ((i % 2) != 0) {
       for (j = 1; j <= i; j++) {  printf("%2c", prnt); } for (s = nos; s >= 1; s--) { //The spacing factor
        if (c == 4 && s == 1) {
         break;
        }
        printf("  ");
       }
       for (k = 1; k <= i; k++) {
        if (c == 4 && k == 5) {
         break;
        }
        printf("%2c", prnt);
       }
       printf("\n");
       nos = nos - 4;  // controls the spacing factor
       ++c;
      }
     }
     return 0;
    }

    Download Code

    Back to top

  5. Write C program to print the following pattern:
    *                         *
       *                   *
    *     *             *     *
       *     *       *     *
    *     *      *      *     *
       *     *       *     *
    *     *             *     *
       *                   *
    *                         *
  6. Program:

    #include
    int main() {
     char prnt = '*';
     int i, j, k, s, p, r, nos = 7;
    
     for (i = 1; i <= 5; i++) {
      for (j = 1; j <= i; j++) {  if ((i % 2) != 0 && (j % 2) != 0) { printf("%3c", prnt); } else if ((i % 2) == 0 && (j % 2) == 0) { printf("%3c", prnt); } else { printf("   "); } } for (s = nos; s >= 1; s--) {  // for the spacing factor
       printf("   ");
      }
      for (k = 1; k <= i; k++) { //Joining seperate figures if (i == 5 && k == 1) {  continue; } if ((k % 2) != 0) { printf("%3c", prnt); } else { printf("   "); } } printf("\n"); nos = nos - 2;   // space control }  nos = 1;  // remaining half.. for (p = 4; p >= 1; p--) {
      for (r = 1; r <= p; r++) { if ((p % 2) != 0 && (r % 2) != 0) { printf("%3c", prnt); } else if ((p % 2) == 0 && (r % 2) == 0) { printf("%3c", prnt); } else { printf("   "); } } for (s = nos; s >= 1; s--) {
       printf("   ");
      }
      for (k = 1; k <= p; k++) {
       if ((k % 2) != 0) {
        printf("%3c", prnt);
       }
    else {
        printf("   ");
       }
      }
      nos = nos + 2;  // space control
      printf("\n");
     }
     return 0;
    }

    Download Code

    Explanation:
    This can be seen as an inverted diamond composed of stars. It can be noted that the composition of this figure follows sequential pattern of consecutive stars and spaces.

    In case of odd row number, the odd column positions will be filled up with ‘*’, else a space will be spaced and vice-versa in case of even numbered row.

    In order to achieve this we will construct four different right angle triangles

    aligned as per the requirement.
    Back to top

  7. Write a C program to print the following pattern:
    *   *   *   *   *
      *   *   *   *
        *   *   *
          *   *
            *
          *   *
        *   *   *
      *   *   *   *
    *   *   *   *   *
  8. Program:

    #include
    int main() {
     char prnt = '*';
     int i, j, s, nos = 0;
     for (i = 9; i >= 1; (i = i - 2)) {
      for (s = nos; s >= 1; s--) {
       printf("  ");
      }
      for (j = 1; j <= i; j++) {
       if ((i % 2) != 0 && (j % 2) != 0) {
        printf("%2c", prnt);
       } else {
        printf("  ");
       }
      }
      printf("\n");
      nos++;
     }
     nos = 3;
     for (i = 3; i <= 9; (i = i + 2)) { for (s = nos; s >= 1; s--) {
       printf("  ");
      }
      for (j = 1; j <= i; j++) {
    
       if ((i % 2) != 0 && (j % 2) != 0) {
        printf("%2c", prnt);
       } else {
        printf("  ");
       }
      }
      nos--;
      printf("\n");
     }
     return 0;
    }

    Download Code
    Back to top

  9. Write a C program to print the following pattern:
              *
            * * *
          * * * * *
        * * * * * * *
      * * * * * * * * *
        * * * * * * *
          * * * * *
            * * *
              *
            * * *
          * * * * *
  10. Program:

    #include
    int main() {
     char prnt = '*';
     int i, j, k, s, nos = 4;
     for (i = 1; i <= 5; i++) { for (s = nos; s >= 1; s--) {
       printf("  ");
      }
      for (j = 1; j <= i; j++) {
       printf("%2c", prnt);
      }
      for (k = 1; k <= (i - 1); k++) { if (i == 1) {     continue; } printf("%2c", prnt); }  printf("\n");   nos--; }  nos = 1; for (i = 4; i >= 1; i--) {
      for (s = nos; s >= 1; s--) {
       printf("  ");
      }
      for (j = 1; j <= i; j++) {
       printf("%2c", prnt);
      }
      for (k = 1; k <= (i - 1); k++) {
       printf("%2c", prnt);
      }
      nos++;
      printf("\n");
     }
     nos = 3;
     for (i = 2; i <= 5; i++) { if ((i % 2) != 0) { for (s = nos; s >= 1; s--) {
        printf("  ");
       }
       for (j = 1; j <= i; j++) {
        printf("%2c", prnt);
       }
      }
      if ((i % 2) != 0) {
       printf("\n");
       nos--;
      }
     }
     return 0;
    }

    Download Code
    Back to top

  11. Write a C program to print the following pattern:
         *
           * *
             * * *
               * * * *
             * * *
           * *
         *
  12. Program:

    /*
        This can be seen as two right angle triangles sharing the same base
        which is modified by adding few extra shifting spaces
    */
    #include
    // This function controls the inner loop and the spacing
    // factor guided by the outer loop index and the spacing index.
    int triangle(int nos, int i) {
     char prnt = '*';
     int s, j;
     for (s = nos; s >= 1; s--) {    // Spacing factor
      printf("  ");
     }
     for (j = 1; j <= i; j++) {      //The inner loop
      printf("%2c", prnt);
     }
     return 0;
    }
    
    int main() {
     int i, nos = 5;
     //draws the upper triangle
     for (i = 1; i <= 4; i++) {  triangle(nos, i);    //Inner loop construction  nos++;              // Increments the spacing factor  printf("\n");  } nos = 7;  //Draws the lower triangle skipping its base. for (i = 3; i >= 1; i--) {
      int j = 1;
      triangle(nos, i);  // Inner loop construction
      nos = nos - j;     // Spacing factor
      printf("\n");
     }
     return 0;
    }

    Download Code
    Back to top

  13. Write a C program to print the following pattern:
    * * * * * * * * *
    * * * *   * * * *
    * * *       * * *
    * *           * *
    *               *
    * *           * *
    * * *       * * *
    * * * *   * * * *
    * * * * * * * * *
  14. Program:

    #include
    
    int main() {
     char prnt = '*';
     int i, j, k, s, nos = -1;
     for (i = 5; i >= 1; i--) {
      for (j = 1; j <= i; j++) {  printf("%2c", prnt); } for (s = nos; s >= 1; s--) {
       printf("  ");
      }
      for (k = 1; k <= i; k++) {
       if (i == 5 && k == 5) {
        continue;
       }
       printf("%2c", prnt);
      }
      nos = nos + 2;
      printf("\n");
     }
     nos = 5;
     for (i = 2; i <= 5; i++) {
      for (j = 1; j <= i; j++) {  printf("%2c", prnt); } for (s = nos; s >= 1; s--) {
       printf("  ");
      }
      for (k = 1; k <= i; k++) {
       if (i == 5 && k == 5) {
        break;
       }
       printf("%2c", prnt);
      }
      nos = nos - 2;
      printf("\n");
     }
     return 0;
    }

    Download Code
    Back to top

  15. Write a C program to print the following pattern:
    * * * * * * * * * * * * * * * * *
      * * * * * * *   * * * * * * *
        * * * * *       * * * * *
          * * *           * * *
            * * * * * * * * *
              * * * * * * *
                * * * * *
                  * * *
                    *
  16. Program:

    #include
    int main() {
     char prnt = '*';
     int i, j, k, s, sp, nos = 0, nosp = -1;
     for (i = 9; i >= 3; (i = i - 2)) {
      for (s = nos; s >= 1; s--) {
       printf("  ");
      }
      for (j = 1; j <= i; j++) { printf("%2c", prnt); } for (sp = nosp; sp >= 1; sp--) {
       printf("  ");
      }
      for (k = 1; k <= i; k++) {  if (i == 9 && k == 1) { continue; } printf("%2c", prnt); } nos++; nosp = nosp + 2; printf("\n"); } nos = 4; for (i = 9; i >= 1; (i = i - 2)) {
      for (s = nos; s >= 1; s--) {
       printf("  ");
      }
      for (j = 1; j <= i; j++) {
       printf("%2c", prnt);
      }
      nos++;
      printf("\n");
     }
    
     return 0;
    }

    Download Code
    Back to top

  17. Write a C program to print the following pattern:
          *
        * * *
      * * * * *
    * * * * * * *
    *           *
    * *       * *
    * * *   * * *
    * * * * * * *
    * * *   * * *
    * *       * *
    *           *
    * * * * * * *
      * * * * *
        * * *
          *
  18. Program:

    #include
    /*
     * nos = Num. of spaces required in the triangle.
     * i   = Counter for the num. of charcters to print in each row
     * skip= A flag for checking whether to
     *       skip a character in a row.
     *
     */
    int triangle(int nos, int i, int skip) {
     char prnt = '*';
     int s, j;
     for (s = nos; s >= 1; s--) {
      printf("  ");
     }
     for (j = 1; j <= i; j++) {
      if (skip != 0) {
       if (i == 4 && j == 1) {
        continue;
       }
      }
      printf("%2c", prnt);
     }
     return 0;
    }
    
    int main() {
     int i, nos = 4;
     for (i = 1; i <= 7; (i = i + 2)) {
      triangle(nos, i, 0);
      nos--;
      printf("\n");
     }
     nos = 5;
     for (i = 1; i <= 4; i++) { triangle(1, i, 0); //one space needed in each case of the formation triangle(nos, i, 1); //skip printing one star in the last row. nos = nos - 2; printf("\n"); } nos = 1; for (i = 3; i >= 1; i--) {
      triangle(1, i, 0);
      triangle(nos, i, 0);
      nos = nos + 2;
      printf("\n");
     }
     nos = 1;
     for (i = 7; i >= 1; (i = i - 2)) {
      triangle(nos, i, 0);
      nos++;
      printf("\n");
     }
     return 0;
    }

    Download Code
    Back to top

  19. Write a C program to print the following pattern:
    * * * * * * * * * * * * * * * * * * * * * * * * *
      *           *   *           *   *           *
        *       *       *       *       *       *
          *   *           *   *           *   *
            *               *               *
          *   *           *   *           *   *
        *       *       *       *       *       *
      *           *   *           *   *           *
    * * * * * * * * * * * * * * * * * * * * * * * * *
  20. Program:

    #include
    
    /*
     * nos = Num. of spaces required in the triangle.
     * i   = Counter for the num. of characters to print in each row
     * skip= A flag for check whether to
     *       skip a character in a row.
     *
     */
    
    int triangle(int nos, int i, int skip) {
     char prnt = '*';
     int s, j;
     for (s = nos; s >= 1; s--) {
      printf("  ");
     }
     for (j = 1; j <= i; j++) {  if (skip != 0) {  if (i == 9 && j == 1) {    continue;  }  } if (i == 1 || i == 9) {  printf("%2c", prnt); } else if (j == 1 || j == i) {  printf("%2c", prnt);  } else {  printf("  "); }  } return 0; } int main() { int i, nos = 0, nosp = -1, nbsp = -1; for (i = 9; i >= 1; (i = i - 2)) {
      triangle(nos, i, 0);
      triangle(nosp, i, 1);
      triangle(nbsp, i, 1);
      printf("\n");
      nos++;
      nosp = nosp + 2;
      nbsp = nbsp + 2;
     }
     nos = 3, nosp = 5, nbsp = 5;
     for (i = 3; i <= 9; (i = i + 2)) {
      triangle(nos, i, 0);
      triangle(nosp, i, 1);
      triangle(nbsp, i, 1);
      printf("\n");
      nos--;
      nosp = nosp - 2;
      nbsp = nbsp - 2;
     }
     return 0;
    }

    Download Code
    Back to top

Over 1600 professionals follow Interview Mantra.


About the Author:  This post was written by Utsav Banerjee. You can reach Utsav on email at fugitiveland@gmail.com


  • Suhani6yadav

    #include
     
    main()
    {
    int n, c, k, space = 1;
     
    printf(“Enter number of rowsn”);
    scanf(“%d”,&n);
     
    space = n – 1;
     
    for ( k = 1 ; k <= n ; k++ )
    {
    for ( c = 1 ; c <= space ; c++ )
    printf(" ");
     
    space–;
     
    for ( c = 1 ; c <= 2*k-1 ; c++)
    printf("*");
     
    printf("n");
     
    }
     
    space = 1;
     
    for ( k = 1 ; k <= n – 1 ; k++ )
    {
    for ( c = 1 ; c <= space; c++)
    printf(" ");
     
    space++;
     
    for ( c = 1 ; c <= 2*(n-k)-1 ; c++ )
    printf("*");
     
    printf("n");
    }
     
    return 0;
    }

  • Rajsharmaj2ee

    give me the code of following  character 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

    pls reply sir code
    regards
    Raj vishwakarma

  • Grissar

    Would someone be able to help with creating a hollow triangle in Java looking like this:
    —-*——-*-*—–*—*—*—–*-*********
    Where the – equals a space. A user enters a number and the triangle height = the number. 
    I have this code so far but I can’t get any further. Not even sure if I’m on the right track anymore: http://pastebin.com/rUrKaVW5 Thanks in advance.

  • Grissar

    The drawing didn’t come out ok. So, here’s a photo.

  • Ajay

    please giv me the code for following pattern!
    1
    11
    21
    1211
    111221
    312211
    13112221

  • Bhomit Davara

    Give me the code of following pattern :
    when we input : 3

              6
           5    4
        3    2     1

  • Dineshrockzzz8

    class pattern21st
    {
        public static void main ()
        {
            for(int i = 1 ; i <=5 ; i++)
            {
                for(int j = 1 ; j =1 ; i–)
            {
                for(int j = 1 ; j <= i ; j++)
                {
                    System.out.print( "*" + " " );
                }
                System.out.println();
            }
        }
    }   

  • Dineshrockzzz8

    class pattern1st
    {
        public static void main ()
        {
            for(int i = 1 ; i <=5 ; i++)
            {
                for(int j = 1 ; j <= i ; j++)
                {
                    System.out.print( "*" + " " );
                }
                System.out.println();
            }
        }
    }   

  • Bindu Kamboj

    #include
    #include
    void main()
    int i,j,k,l,a=1,d=2,x;
    char p=’A';
    for(i=1;i<=6-1;i++)
    {
      for(j=1;j<=7-i;j++)
      {
        printf("%c",p);
        p++;
      }
    x=a+(i-1)*d;
     for(k=1;k<=x;k++)
      {
        printf(" ");
      }
     for(l=1;l<=7-i;l++)
     {
       printf("%c",p-1);
       p–;
     }
    printf("n");
    }
    getch();
    }

  • Bindu kamboj

    #include
    void main()
    {
    int i,j,a=1;
    for(i=1;i<=4;i++)
     {
      for(j=1;j<i+1;j++)
       {
       printf("%d",a);
       a++;
       }
    printf("n");
     }
    getch();
    }

  • Bindu kamboj

    #include
    void main()
    {
    int i,j,a=1;
    for(i=1;i<=4;i++)
     {
      for(j=1;j<i+1;j++)   {
       printf(“%d”,a);
       a++;
       }
    printf(“n”);
     }
    getch();
    }

  • Bindu kamboj

    #include
    void main()
    {
    int i,j,a=6;
    for(i=1;i<=3;i++)
     {
      for(j=1;j<i+1;j++)   {
       printf(“%d”,a );
       a–;
       }
    printf(“n”);
     }
    getch();
    }

  • Angad tomar

    for(i=n;i>0;i–)
    {
      printf(”  ”);
      for(j=1;j<=i;j++)
      {
        printf("*");

      }
      printf("n");

    }

  • Jayesh5101992sapkale

    Hi Hari ,,,,,Check this code in c language……….if any Error Plz Fix it….

    Code:

    #include #include int first_term=1;void main(){int a[100][100];int c=1,i=0,j=0,k=0,m=0,n=0,x=0;clrscr();printf(“Enter the number of rows and columns for the square matrix n”);scanf(“%d”,&n);x=n;while(n>=1){for(k=0;k<n;k++)if(first_term){a[m][k+m]=c++;}else{a[m][k+m]=0;}for(k=1;k=0;k–)if(first_term){a[n-1+m][k+m]=c++;}else{a[n-1+m][k+m]=0;}for(k=n-2;k>0;k–)if(first_term){a[k+m][m]=c++;}else{a[k+m][m]=0;}if(x==n){first_term=0;}n-=2;m++;}for(i=0;i<x;i++){for(j=0;j<x;j++){  if(a[i][j]==0){printf("     ");}  else{printf("    *") ;}}printf("n");}getch();}

  • Jayesh5101992sapkale

    sorry this is not suitable.,,,,I will provide in to parts

  • Jayesh5101992sapkale

    #include
    #include

    int first_term=1;

    void main()
    {
    int a[100][100];int c=1,i=0,j=0,k=0,m=0,n=0,x=0;clrscr();
    printf(“Enter the number of rows and columns for the square matrix n”);scanf(“%d”,&n);x=n;

  • Jayesh5101992sapkale

    can U give your Email id I Will Send u program solution  b-coz content not Fit on it,,,,,,,,,,,,,,,,If You have Already Solved this problem then Very Good Try………..

  • Jayesh5101992sapkale

    int first_term=1;

    void main()
    {

    int a[100][100];
    int c=1,i=0,j=0,k=0,m=0,n=0,x=0;

    clrscr();
    printf(“Enter Rows and columns for the square matrix n”);
    scanf(“%d”,&n);
    x=n;
    while(n>=1)
    {
    for(k=0;k<n;k++)
    if(first_term){a[m][k+m]=c++;}
    else{a[m][k+m]=0;}

    for(k=1;k=0;k–)
    if(first_term){a[n-1+m][k+m]=c++;}
    else{a[n-1+m][k+m]=0;}

    for(k=n-2;k>0;k–)
    if(first_term){a[k+m][m]=c++;}
    else{a[k+m][m]=0;}

    if(x==n){
    first_term=0;}
    n-=2;
    m++;

    }

    for(i=0;i<x;i++)
    {
    for(j=0;j<x;j++)
    {
      if(a[i][j]==0){printf("     ");}
      else{printf("    *") ;}
    }

    printf("n");
    }
    getch();
    }

  • Jayesh5101992sapkale

    Remove all last line from it

  • Nkkoolguy

    *

    * *

     
    *

    * * * *

        *

        * *

          *

    * * * * * * * *

            *

            * *

              *

            * * * *

                *

                * *

                  *Plz tell the code to get this pattern

  • Ridzi0207

    plz tell me the code for
    *******
    *******
         ***
           *
         ***
    *******

  • Aarthi

    want in java programming…

  • Dsasd

    #include
    void main()
    {
    printf(“H           H       EEEEE    L                 L                      OOOOH           H       E               L                 L                   O           OH           H       E               L n”);
    printf(“      L                   O            OHHHHH        EEEEE     L                 L                   O           OH           H       E                L                 L                   O           OHn”);
    printf(“          H       E                L                 L                   O           OH           H       EEEEE      LLLLL       LLLLL        OOOOOn”);
    }

  • Ankita

    #include#includeint main(){      int i,j,k,l;    
          for(j=0;j<=5;j++)      printf("*");       for(i=0;i<=2;i++)      {      printf("nn");      for(k=0;k<=1;k++)      printf("* ");      }      printf("nn");      for(l=0;l<=5;l++)      printf("*");            getch();
    }

  • ankita srivastava

    #include#include
    int main()
    {      int i,j,k,l;    
          for(j=0;j<=5;j++)
          printf("*");
           for(i=0;i<=2;i++)      {
          printf("nn");
          for(k=0;k<=1;k++)
          printf("* ");
          }
          printf("nn");
          for(l=0;l<=5;l++)
          printf("*");            getch();
    }

  • ankita

    #include
    #includeint main(){      int i,j,k,l;           for(i=0;i<=2;i++)      {      printf("nn");      for(k=0;k<=1;k++)      printf("* ");      }      printf("nn*"); 
     for(j=0;j<=2;j++)      {      printf("nn");      for(l=0;l<=1;l++)      printf("* ");}                  getch();
    }

  • Ankita

    #include
    #include
    void main()
    {

    int i,j,k,l,m,n,o;{
    for(i=0;i<=1;i++){printf("n");
    for(j=0;j<=6;j++)
    printf("*");}for(k=0;k<=1;k++){printf("n");for(l=0;l<=1+k;l++)printf(" ");for(m=0;m<=2-2*k;m++)printf("*");}printf("n  ***n");for(o=0;o<=6;o++){printf("*");}}getch();}

  • Haemobindium

    please tell me the c code for the following pattern

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

  • Mrasheed_22

    give me the code 
    *
    *2
    *2*
    *2*4
    *2*4*8
    *2*4*8*

  • Anant

    #include
    main()
    {
    int i,j;
    for(i=1;i=i;j–)
    {
    printf(“%d”,j);
    }
    printf(“n”);
    }
    }

  • Anant

    #include
    main()
    {
    int i,j;
    for(i=1;i=i;j–)
    {
    printf(“*”);
    }
    printf(“n”);
    }
    }

  • programing slave

    hi please what’s the code of this output.

                                                             *
                                                           ***
                                                         *****
                                 ****************************
                                   **************************
                                        **********************
                                            *****************                                         ***************
                                             ******      *****
                                             ****             ****
                                            ***                   ***
                                          *                               *or a star shape.. please help..  pleaseee

  • Rasmi Ranjan Nayak

    2.

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

    #include
    #include
    int main()
    {
        int i, j, cnt, max, k;
        k = 0;
        max = 10;
        for(j = 0; j < 4; j++)
        {
        for(i = 0; i <= max; i++)
        {
            if((i =(max – k)))
            {
                printf(“*”);
            }
            else
            {
                printf(” “);
            }
            printf(” “);
         }
         printf(“n”);
         k = k + 2;
        }

        return 0;
    }

  • Chinnadev639

    i have  one problem
    1
    2   4
    4    7        8
    10   16    13    32

  • Anus425

    i want the coding of this pattern
                                         1
                                      212
                                   32123
                                 4321234
                               543212345
                                  4321234
                                    32123
                                      212
                                         1

  • Rishbahsaini01

    very nice i very like it 

  • Dilip verma

    #include
    #include
    main()
    {
          int i,j;
          for(i=0;i<4;i++)
          {
             printf("n");
             for(j=0;j<=i;j++);
             {
             printf("*");
             }
            
             }
             getch();
             }
    i could not print progm like u . what is happening with me. plz tell me….

  • DHANAVELTHANGAVEL

    any body know the program please reply me. i attend one interview second round execution round asking this type of output…..i try but i can not give correct output. so, i rejected that interview

  • DHANAVELTHANGAVEL

    it is useful for all

  • DHANAVELTHANGAVEL

    #include
    void main()
    {

    char x[100];
    int i,n,j,a,k;
    clrscr();
    printf(“Enter the stringn”);
    gets(x);
    n=strlen(x);
    for(i=0;i<n;i++)
    {
    for(a=i;a=0;j–)
    printf(“%c”,x[j]);
    for(k=1;k=0;i–)
    {
    for(a=n-i-1;a>0;a–)
    printf(” “);
    for(j=i;j>=0;j–)
    printf(“%c”,x[j]);
    for(k=1;k<=i;k++)
    printf("%c",x[k]);
    printf("n");
    }

    getch();
    }

  • DHANAVELTHANGAVEL

    #include
    void main()
    {

    int i,n,j,a,k;

    clrscr();
    printf(“Enter the numbern”);
    scanf(“%d”,&n);
    for(i=1;i<=n;i++)
    {
    for(a=i;a=1;j–)
    printf(“%d”,j);
    for(k=2;k0;i–)
    {
    for(a=n-i;a>=1;a–)
    printf(” “);
    for(j=i;j>0;j–)
    printf(“%d”,j);
    for(k=2;k<=i;k++)
    printf("%d",k);
    printf("n");
    }

    getch();
    }

  • Harshal Sawant

    want code for above pattern

    *
       * *
           *  *
                  *
           *  *
       * *
    *

  • DHANAVELTHANGAVEL

    //maventic infotech
    #include
    void main()
    {
    char s=’*';
    int i,j,k,l,m,n;
    clrscr();
    printf(“Enter the valuen”);
    scanf(“%d”,&n);
    for(i=1;ii;j–)
    {
    printf(” “);
    }
    for(k=i;k>=1;k–)
    {
    if(i=1)
    printf(“%2c”,s);
    else
    printf(” “);
    }
    }
    for(l=2;l<=i;l++)
    {
    if(i<=n)
    printf("%2c",s);
    else
    {
    m=l-n;
    if(m0;i–)
    {
    for(j=(2*n);j>i;j–)
    printf(” “);
    for(k=1;k<=i;k++)
    {
    if(i=n)
    printf(“%2c”,s);
    else
    printf(” “);
    }
    }
    for(l=2;l<=i;l++)
    {
    if(i<=n)
    {
    printf("%2c",s);
    }
    else
    {
    m=l-n;
    if(m<=0)
    printf(" ");
    else
    printf("%2c",s);
    }
    }
    printf("n");
    }
    getch();
    }

  • DHANAVELTHANGAVEL

    #include
    void main()
    {
    char s=’*';
    int i,j,k,l,m,n;
    clrscr();
    printf(“Enter the valuen”);
    scanf(“%d”,&n);
    for(i=1;ii;j–)
    printf(”  ”);
    for(k=i;k>=1;k–)
    printf(“%2c”,s);
    for(l=2;l0;i–)
    {
    for(j=(2*n);j>i;j–)
    printf(”  ”);
    for(k=1;k<=i;k++)
    printf("%2c",s);
    for(l=2;l<=i;l++)
    printf("%2c",s);
    printf("n");
    }
    getch();
    }

  • DHANAVELTHANGAVEL

    #include
    void main()
    {
            int i,j,k,n;
            clrscr();
            printf(“Enter the n valuen”);
            scanf(“%d”,n);
            for(i=1;i1;j–)
                    {
                          printf(” “);
                     }
                    for(k=n-i;k>=0;k–)
                      {
                                printf(“*”);
                       }
               printf(“n”);
             }
    getch();
    }

  • Rahul Hendawe

    Give code for following  o/p:

    A                              A
    AB                         BA
    ABC                    CBA
    ABCD             DCBA
    ABCDE        EDCBA
    ABCDEF   FEDCBA
    ABCDEFGFEDCBA

    PLZ REPLY .

  • Durgeshb12

    plz tell me code for following pattern

    *
    **
       **
           *

  • DHANAVELTHANGAVEL

    #include
    void main()
    {
    int i,j,k,l,m,n;
    char x[10]=”abcdefg”;
    clrscr();
    n=strlen(x);
    for(i=0;i<n;i++)
    {
    for(j=0;ji+1;k–)
    {
    printf(” “);
    }
    for(l=n-1;l>i+1;l–)
    {
    printf(” “);
    }
    for(m=i;m>=0;m–)
    {
    if(m==n-1)
    continue;
    printf(“%c”,x[m]);
    }
    printf(“n”);

    }
    getch();
    }

  • Rocks Shrey

    aaaaaaa
    a           a
     a         a
      a      a
           a
    give me a answer of this program

  • Sureshgk69

    tanx …nice explain…

Previous post:

Next post: