10 Challenging number pattern programs in C

by Utsav Banerjee on November 8, 2009


This is a continuation to the series of challenging pattern C programs in Interview Mantra. This set of 10 puzzling programs are of type number patterns.

Also read Print Pattern Programs

  1. Write a C program to print the following pattern:
    1
    0 1
    1 0 1
    0 1 0 1
    1 0 1 0 1
  2. Write a C program to print the following pattern:
    0
    1 1
    2 3 5
    8 13 21
  3. Write a C program to print the following pattern:
    1
    121
    12321
    1234321
    12321
    121
    1
  4. Write a C program to print the following pattern:
           2
         4 5 6
       6 7 8 9 10
         4 5 6
           2
  5. Write a C program to print the following pattern:
     1                         1
     3 3 3                 3 3 3
     5 5 5 5 5         5 5 5 5 5
     7 7 7 7 7 7 7 7 7 7 7 7 7 7
     5 5 5 5 5         5 5 5 5 5
     3 3 3                 3 3 3
     1                         1
  6. Write a C program to print the following pattern:
        0
     -2-3 0
    -4-3-2-1 0
     -2-3 0
        0
  7. Write a C program to print the following pattern:
    77777777777
             7
            7
           7
          7
         7
        7
       7
      7
     7
    7
  8. Write a C program to print the following pattern:
     1                       1
     1 0                   1 0
     1 0 1               1 0 1
     1 0 1 0           1 0 1 0
     1 0 1 0 1       1 0 1 0 1
     1 0 1 0 1 0   1 0 1 0 1 0
     1 0 1 0 1 0 1 0 1 0 1 0 1
     1 0 1 0 1 0   1 0 1 0 1 0
     1 0 1 0 1       1 0 1 0 1
     1 0 1 0           1 0 1 0
     1 0 1               1 0 1
     1 0                   1 0
     1                       1
  9. Write a C program to print the following pattern:
    1
    2 4
    3 6 9
    2 4
    1
  10. Write a C program to print the following pattern:
     1
     1 0
     1 0 0
     1 0 0 0
     1 0 0 0 0
     1 0 0 0 0 0
     1 0 0 0 0 0 0
     1 0 0 0 0 0
     1 0 0 0 0
     1 0 0 0
     1 0 0
     1 0
     1

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

    Program:

    #include <stdio.h>
    
    int main(void) {
     int i, j;
     for (i = 0; i < 4; i++) {
      for (j = 0; j <= i; j++) {
       if (((i + j) % 2) == 0) {  // Decides on as to which digit to print.
        printf("0");
       } else {
        printf("1");
       }
       printf("\t");
      }
      printf("\n");
     }
     return 0;
    }

    Download Code

    Explanation: This is a right angle triangle composed of 0′s and 1′s.
    Back to top

    End of Question1 Start of Question2

  3. Write C program to print the following pattern:
    0
    1 1
    2 3 5
    8 13 21
  4. Program:

    #include <stdio.h>
    
    int main(void) {
     int i, j, a = 0, b = 1, temp = 1;
     for (i = 1; i <= 4; i++) {
      for (j = 1; j <= i; j++) {
       if (i == 1 && j == 1) { // Prints the '0' individually first
        printf("0");
        continue;
       }
       printf("%d ", temp);  // Prints the next digit in the series
       //Computes the series
       temp = a + b;
       a = b;
       b = temp;
       if (i == 4 && j == 3) { // Skips the 4th character of the base
        break;
       }
      }
      printf("\n");
     }
     return 0;
    }

    Download Code

    Explanation: This prints the Fibonacci series in a right angle triangle formation where the base has only three characters.
    Back to top

    End of Question2 Start of Question3

  5. Write C program to print the following pattern:
    1
    121
    12321
    1234321
    12321
    121
    1
  6. Program:

    #include <stdio.h>
    
    void sequence(int x);
    int main() {
     /* c taken for columns */
     int i, x = 0, num = 7;
     for (i = 1; i <= num; i++) {
      if (i <= (num / 2) + 1) {
       x = i;
      } else {
       x = 8 - i;
      }
      sequence(x);
      puts("\n");
     }
     return 0;
    }
    
    void sequence(int x) {
     int j;
    
     for (j = 1; j < x; j++) {
      printf("%d", j);
     }
     for (j = x; j > 0; j--) {
      printf("%d", j);
     }
    }

    Download Code
    Back to top

    End of Question3 Start of Question4

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

    #include <stdio.h>
    
    int main(void) {
     int prnt;
     int i, j, k, r, s, sp, nos = 3, nosp = 2; //nos n nosp controls the spacing factor
     // Prints the upper triangle
     for (i = 1; i <= 5; i++) {
      if ((i % 2) != 0) {
       for (s = nos; s >= 1; s--) {
        printf("  ");
       }
       for (j = 1; j <= i; j++) {
        if (i == 5 && j == 5) { //Provides the extra space reqd betn 9 n 10
         printf(" ");        // as 10 is a 2 digit no.
        }
        prnt = i + j;
        printf("%2d", prnt);
       }
      }
      if ((i % 2) != 0) {
       printf("\n");
       nos--;
      }
     }
     // Prints the lower triangle skipin its base..
     for (k = 3; k >= 1; k--) {
      if ((k % 2) != 0) {
       for (sp = nosp; sp >= 1; sp--) {
        printf("  ");
       }
       for (r = 1; r <= k; r++) {
        prnt = k + r;
        printf("%2d", prnt);
       }
      }
      if ((k % 2) != 0) {
       printf("\n");
       nosp++;
      }
     }
     return 0;
    }

    Download Code

    Explanation: This is a diamond formation composed of numbers. The numbers are in the following order next_no=i+j where
    next_no = The next no to be printed
    i = index of the outer for loop
    j = index of the inner for loop
    Back to top

    End of Question4 Start of Question5

  9. Write a C program to print the following pattern:
     1                           1
     3 3 3                   3 3 3
     5 5 5 5 5           5 5 5 5 5
     7 7 7 7 7 7 7   7 7 7 7 7 7 7
     5 5 5 5 5           5 5 5 5 5
     3 3 3                   3 3 3
     1                           1
  10. Program:

    #include <stdio.h>
    
    int main(void) {
     int i, j, k, s, p, q, sp, r, c = 1, nos = 13;
     for (i = 1; c <= 4; i++) {
      if ((i % 2) != 0) {   // Filters out the even line nos.
       for (j = 1; j <= i; j++) { // The upper left triangle
        printf("%2d", i);
       }
       for (s = nos; s >= 1; s--) {  // The spacing factor
        printf("  ");
       }
       for (k = 1; k <= i; k++) { // The upper right triangle
        printf("%2d", i);
       }
       printf("\n");
       nos = nos - 4;  // Space control
       ++c;
      }
     }
     nos = 10;  // Space control re intialized
     c = 1;
     for (p = 5; (c < 4 && p != 0); p--) {
      if ((p % 2) != 0) {  // Filters out the even row nos
       for (q = 1; q <= p; q++) {  // Lower left triangle
        printf("%2d", p);
       }
       for (sp = nos; sp >= 1; sp--) { // Spacing factor
        printf(" ");
       }
       for (r = 1; r <= p; r++) {  // Lower right triangle
        printf("%2d", p);
       }
    
       printf("\n");
       --c;
       nos = nos + 8;  // Spacing control.
      }
     }
    
     return 0;
    }

    Download Code

    Explanation: Here we are printing only the odd row nos along with thier respective line number. This structure can divided into four identical right angle triangles which are kind of twisted and turned placed in a particular format .
    Back to top

    End of Question5 Start of Question6

  11. Write a C program to print the following pattern:
        0
     -2-3 0
    -4-3-2-1 0
     -2-3 0
        0
  12. Program:

    #include <stdio.h>
    
    int main(void) {
     int i, j, k, r, s, sp, nos = 2, nosp = 1;
     for (i = 1; i <= 5; i++) {
      if ((i % 2) != 0) {
       for (s = nos; s >= 1; s--) {  //for the spacing factor.
        printf("  ");
       }
       for (j = 1; j <= i; j++) {
        printf("%2d", j-i);
       }
      }
      if ((i % 2) != 0) {
       printf("\n");
       nos--;
      }
     }
     for (k = 3; k >= 1; k--) {
      if ((k % 2) != 0) {
       for (sp = nosp; sp >= 1; sp--) {  // for the spacing factor.
        printf("  ");
       }
       for (r = 1; r <= k; r++) {
        printf("%2d", r-k);
       }
      }
      if ((k % 2) != 0) {
       printf("\n");
       nosp++;
      }
     }
     return 0;
    }

    Download Code

    Explanation:This can be seen as a diamond composed of numbers. If we use the conventional nested for loop for its construction the numbers can be seen to flowing the following function f(x) -> j-i
    where
    j= inner loop index
    i= outer loop index
    Back to top

    End of Question6 Start of Question7

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

    #include <stdio.h>
    
    int main(void) {
     int i, j;
     for (i = 11; i >= 1; i--) {
      for (j = 1; j <= i; j++) {
       if (i == 11) {
        printf("7");  // Makes sure the base is printed completely
        continue;
       } else if (j == i) { // Hollows the rest
        printf("7");
       } else {
        printf(" ");
       }
      }
      printf("\n");
     }
     return 0;
    }

    Download Code

    Explanation: This can be seen as a hollow right-angled triangle composed of 7′s
    Back to top

    End of Question7 Start of Question8

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

    #include <stdio.h>
    
    int main(void) {
        int i,j,k,s,nos=11;
        for (i=1; i<=7; i++) {
            for (j=1; j<=i; j++) {
                if ((j%2)!=0) {   // Applying the condition
                    printf(" 1");
                } else {
                    printf(" 0");
                }
            }
            for (s=nos; s>=1; s--) {  // Space factor
                printf("  ");
            }
            for (k=1; k<=i; k++) {
                if(i==7 && k==1)  // Skipping the extra 1
                {
                    continue;
                }
                if ((k%2)!=0) {  // Applying the condition
                    printf(" 1");
                } else {
                    printf(" 0");
                }
            }
            printf("\n");
            nos=nos-2;  // Space Control
        }
         nos=1;
         for ( i=6; i>=1; i--) {  // It shares the same base
             for (j=1; j<=i; j++) {
                 if (j%2!=0) {
                     printf(" 1");
                 } else {
                     printf(" 0");
                 }
             }
             for(s=nos; s>=1; s--)  // Spacing factor
             {
                 printf("  ");
             }
             for (k=1; k<=i; k++) {
                 if (k%2!=0) {
                     printf(" 1");
                 } else {
                     printf(" 0");
                 }
             }
             printf("\n");
             nos=nos+2;
         }
        return 0;
    }

    Download Code
    Back to top

    End of Question8 Start of Question9

  17. Write a C program to print the following pattern:
    1
    2 4
    3 6 9
    2 4
    1
  18. Program:

    #include <stdio.h>
    int main(void) {
        int i,j;
        for (i=1; i<=3 ; i++) {
            for (j=1; j<=i; j++)  {
                printf("%2d", (i*j));
            }
            printf("\n");
        }
        for (i=2; i>=1; i--) { // As they share the same base
            for (j=1; j<=i; j++)  {
                printf("%2d",i*j);
            }
            printf("\n");
        }
        return 0;
    }

    Download Code

    Explanation: This can be seen as two right angle triangles sharing th same base
    The numbers are following the following function f(x) = i *j
    where
    i = Index of the Outer loop
    j = Index of the inner loop
    Back to top

    End of Question9 Start of Question10

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

    #include <stdio.h>
    
    int main(void) {
        int i,j;
        for (i=1; i<=7; i++) {
            for (j=1; j<=i; j++) {
                if (j==1) {           // Applying the condition
                    printf(" 1");
                } else {
                    printf(" 0");
                }
            }
            printf("\n");
        }
        for (i=6; i>=1; i--) {  //As it shares the same base i=6
            for (j=1; j<=i; j++) {
                if (j==1) {   // Applying the condition
                    printf(" 1");
                } else {
                    printf(" 0");
                }
            }
            printf("\n");
        }
        return 0;
    }

    Download Code

    Explanation: This can be seen as two right angle triangles sharing the same base which is composed of 0′s n 1′s. The first column is filled with 1′s and rest with 0′s
    Back to top End of Question10

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


2,250 readers have already subscribed to email updates!

Enter your email address:

  • Ramesh S

    Excellent article!!! Thanks a lot this.

  • http://rapidlinksbyannu.blogspot.com darkmessiah

    yeah
    helped me a lot
    very nice.

  • Arun lal

    i have a problem
    1 1
    12 21
    123 321
    1234 4321
    12345 54321
    123456 654321
    1234567 7654321
    12345678 87654321
    123456789 987654321

  • rohan

    thankyou sir,,,for posting these patterns,,,these help me a lot on my exercises…thanks one again

  • ria

    1
    23
    456
    78910
    456
    23
    1

  • arnab

    write a program in c that will print the number divisible by 3 not by 9.please help me

  • swapnil

    1 1
    12 21
    123 321
    1234 4321
    12345 54321
    123456 654321
    1234567 7654321
    12345678 87654321
    123456789 987654321

  • sweety

    can someone help me with the following code.
    1
    212
    32123
    4321234
    543212345
    4321234
    32123
    212
    1

  • sunny

    i have an assignment of this program . Please help me
    1
    1,2
    1,2,3
    1,2,3,4
    1,2,3……

  • ravi

    pls help me…
    how can we make this pattern.
    if n=5(n is inputted by user.)
    then this pattern will be displayed.
    55555
    54444
    54333
    54322
    54321

  • http://naveenthakur200@gmail.com NAVEEN

    Write a program to print the following pattern:
    1
    12
    123
    1234
    12345

  • rahul

    sir please help me in c I am beginner in c language so give me well concept of this program.
    1234554321
    1234 4321
    123 321
    12 21
    1 1

  • vinayak

    Thank you very much sir for posting these comments ,
    these programs help me a lot for my exercise………….

  • vinayak

    Sir help me for this pattern please,
    1 1
    4 4
    16
    64 64
    256 256

  • joel

    sir i have this pattern so please help me
    1
    22
    333
    4444
    55555

  • http://google.com zeba

    i want code for following pattern

    A1
    B2 , C3
    D4, E5, F6
    G7 , H8 I9, J10.

  • http://google.com zeba

    plz help me for writing code for following pattern

    A1
    B2 , C3
    D4, E5, F6
    G7 , H8 I9, J10.

  • sakshi

    plz help me to print-
    1
    2 3
    4 5 6
    7 8 9 10
    11 12 13 14 15

  • Rahila Vora

    write a program to print the following not using FOR loop
    1
    12
    123
    1234
    12345
    . . . . . . . . .
    in OPEN SOURCE PROGRAMMING

  • sankalan ghosh

    i have a problem to print pattern as below

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

  • Cryus

    hey sakshi here’s ur solution……

    #include
    #include

    void main()
    {
    int i,j;
    clrscr();

    for(i=1;i<=5;i++)
    {
    for(j=1;j<=i;j++)
    {
    printf("%d",j);
    }
    printf("\n");
    }
    getch();
    }

  • Cryus

    hey can any1 tell how to run c compiler in windows for save file…..pls its urgent!!!

  • Cryus

    do any1 hav “guts” 2 write coding of this patterns…

    1 2 3
    8 9 4
    7 6 5

    really in need for this 1……plz help??? :)

  • trisha

    1
    232
    34543
    4567654 can u do dis?

  • saloni

    1
    3 2
    6 5 4
    10 9 8 7

  • nivya

    i have a problem to print the following pattern
    5 4 3 2 1
    4 3 2 1
    3 2 1
    2 1
    1

  • Nitin Kumar

    Write a program to print the bellow pattern. . . . .

    1
    2 3
    4 5 6
    7 8 9 10

  • Manikantha

    can any one tell how to print this pattern??????????
    01 02 03 04 05
    16 17 18 19 06
    15 24 25 20 07
    14 23 22 21 08
    13 12 11 10 09

  • http://interviewmantra sarvesh

    hey i have problem solve for me
    1
    2 1 2
    3 2 1 2 3
    4 3 2 1 2 3 4
    3 2 1 2 3
    2 1 2
    1

  • http://interviewmantra sarvesh

    solve this for me

  • NagaSindhura

    1
    2 1 2
    3 2 1 2 3
    4 3 2 1 2 3 4
    3 2 1 2 3
    2 1 2
    1
    solve this for me………………………..

  • foram

    1
    4 2
    10 8 6
    18 16 14 12
    plz help me to make this pattern

  • jaspreet pannu

    please help me print the following pattern ;
    123454321
    1234 4321
    123 321
    12 21
    1 1

  • prashant

    Write a program to print the bellow pattern. . . .

    *
    * *
    * * *
    * *
    *

  • prashant

    *
    * *
    * * *
    * *
    *

  • priyanka

    1
    2 3
    4 5 6
    7 8 9 10

  • Mahendra Badhan

    Hi I am Mahendra ,Prashant Ur Solution is Here Now
    #include
    #include
    void main()
    {
    int i,j,n;
    clrscr();
    printf(“\n Enter the number :”);
    scanf(“%d”,&n);
    for(i=n;i>0;i–)
    {
    for(j=i;j<=n;j++)
    {
    printf("*");
    }
    printf("\n");
    }
    for(i=0;i<=n;i++)
    {
    for(j=i;j<n-1;j++)
    {
    printf("*");
    }
    printf("\n");
    }
    getch();
    }
    /*
    Enter the number :5
    *
    **
    ***
    ****
    *****
    ****
    ***
    **
    *
    */

  • http://www.interviewmantra.net Mahendra Badhan

    Hey Sankalan Ghosh Ur Solution is ….

    #include
    #include
    void main()
    {
    int i,j,n;
    clrscr();
    printf(“\n Enter the Number :”);
    scanf(“%d”,&n);
    for(i=0;i<n;i++)
    {
    for(j=i;j<n;j++)
    {
    printf("*");
    }
    printf("\n");
    }
    getch();
    }
    /* OUTPUT:

    Enter the Number :5
    Output:
    *****
    ****
    ***
    **
    *
    From Mahendra Badhan..
    */

  • saranya

    plse help me in this program
    1
    2 2
    3 3 3
    4 4 4 4
    5 5 5 5 5

  • srs

    i want to know the solution of this numerical pattern
    1
    2 3
    4 5 6
    7 8 9 10

  • Milind Deshkar

    i want to know the solution of this numerical pattern
    1
    2 3
    4 5 6
    7 8 9 10

  • vikee singh

    //saranya
    #include
    void main()
    {
    int i,j;
    for(i=1;i<=5;i++)
    {
    for(j=1;j<=i;j++)
    printf("%d",i);
    printf("\n");
    }
    }

  • vikee singh

    //nivya
    #include
    void main()
    {
    int i,j;
    for(i=5;i>=1;i–)
    {
    for(j=i;j>=1;j–)
    printf(“%d”,j);
    printf(“\n”);
    }}

  • aniket

    2
    34
    567
    8910
    plz solve it///fast plz

  • paNKAJ LIMBACHIYA

    2
    34
    567
    8910

    PLZ SOLVE IT I M FROM BARDOLI SOLVE FAST

  • muthprabha

    *
    * *
    * * *
    * * * *

  • ammu

    *
    * *
    * *
    * *

  • Indu

    Can you help with the solution for the below pattern

    if n=5

    1 2 3 4 5
    16 17 18 19 6
    15 24 25 20 7
    14 23 22 21 8
    13 12 11 10 9

  • Vinod Mishra

    Can you give code for

    1
    1 1
    1 2 1
    1 3 3 1
    1 4 6 4 1

    and so on,
    thank you.

  • divya

    sir pls help me to print this
    1
    2 1 2
    3 2 1 2 3
    2 1 2
    1

  • Ronak Patel

    This Is Also Worked ….
    #include
    #include

    void main()
    {
    int i,j,k,n;
    clrscr();
    printf(“input number “);
    scanf(“%d”,&n);
    clrscr();
    for(k=1;k<=n;k++)
    {
    for(j=1;j0;k–)
    {
    for(j=1;j<=k;j++)
    {
    printf("%d",k*j);
    }
    printf("\n");
    }
    getch();
    }

  • http://www.freshnget.com Puneet

    Really helpful

  • Rajitha

    1
    1 2
    1 3
    1 4
    can any one do this??????????????

  • Rajitha

    1
    1–2
    1—–3
    1——–4

  • jay

    please give code for….this program in c…..
    if n=2….
    1234
    8675

  • jainam

    how to print this…
    1
    2 3
    4 5 6
    7 8 9 10

  • narayana

    4 4
    3 3
    2 2
    1 1
    0
    1 1
    2 2
    3 3
    4 4

  • S.V.Ramana

    hi
    jay
    i have code 4 your output
    let it check

    #include
    #include
    void main()
    {
    int i,j,n;
    clrscr();
    int k=1;
    printf(“Enter no of line : “);
    scanf(“%d”,&n);
    for(i=0;i<n;i++)
    {
    for(j=0;j<4;j++)
    {
    printf("%d \t",k);
    k++;
    }
    printf("\n");
    }
    getch();
    }

  • S.V.Ramana

    hi
    jainam
    good morning

    this is code for ur output
    printing like
    1
    2 3
    4 5 6
    7 8 9 10

    #include
    #include
    void main()
    {
    int i,j,n;
    clrscr();
    int k=1;
    printf(“Enter no of line : “);
    scanf(“%d”,&n);
    for(i=0;i<n;i++)
    {
    for(j=0;j<=i;j++)
    {
    printf("%d \t",k);
    k++;
    }
    printf("\n");
    }
    getch();
    }

  • S.V.Ramana

    hi
    Rajitha mam

    good morning

    this is code for your output
    1
    12
    13
    14

    #include
    #include
    void main()
    {
    int i,j,n,a,b;
    clrscr();
    a=1;
    b=1;
    for(i=1;i<=3;i++)
    {
    for(j=1;j4)
    break;
    printf(“%d%d”,a,b);
    printf(“\n”);

    }
    }
    getch();

    }

  • S.V.Ramana

    hi
    Mr.Narayana

    This is the code for generating your output like
    44
    33
    22
    11
    0
    11
    22
    33
    44

    program:
    —————-
    #include
    #include
    void main()
    {
    int i,j,n;
    printf(“Enter n value : “);
    scanf(“%d”,&n);
    for(i=n;i>=0;i–)
    {
    for(j=2;j>0;j–)
    {
    if(i==0)
    {
    printf(“%d”,i);
    break;
    }
    printf(“%d”,i);
    }
    printf(“\n”);
    }
    for(i=1;i<=4;i++)
    {
    for(j=1;j<=2;j++)
    {
    printf("%d",i);
    }
    printf("\n");
    }
    getch();
    }

  • tarun

    Hey, can please anyone solve this-

    in input is 4 then:
    1
    1 2
    3 4 5
    12 13 14 15

    where next line begins with the sum of previous line’s elements and increased by 1.

  • sanjay kamdar

    how i print following output… plz immediately solve my problem guys… i have an exam tomorrow…

    1
    2 3
    4 5 6
    7 8
    9

  • Sridhar Jammalamadaka

    @Sanjay Kamdar,

    int main()
    {
    int i, j, k = 1;

    for(i=0;i<5;i++)
    {
    for(j=0; j<3; j++)
    {
    if((j<=i) && ((i+j) <=4))
    {
    printf(“%d \t”,k);
    k++;
    }
    }
    printf(“\n”,j);
    }
    return 0;
    }

  • http://gmail kusum

    how to print the pattern
    a. 1
    2 3
    4 5 6
    7 8 9 10

    b 1
    1 1
    1 2 1
    1 3 3 1
    1 4 6 4 1
    plese help me

  • Nikhil Nambiar

    #include
    main()
    {
    int i,j;

  • Nikhil Nambiar

    main()
    {
    int i,j;
    for(i=1;i<=5;i++)
    {
    for(j=i;j<=i;j++)
    {
    printf("%d",i);
    printf("n");
    }
    }
    }

  • Bhagyesh

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

  • sandhya

    how to print the pattern
    0
    0 1
    0 1 2
    0 1 2 3
    0 1 2 3 4

  • Asira

    hey cn u give me a program to display “s” in 5 rows nd 5 columns plz its vry urgent yaar

  • kaye1711

    plss help i need to print an inverted fibonacci triangle

  • Harshit Srivastava

    i like it

  • Harshit Srivastava

    it is useful!

  • Harshit Srivastava

    hie.

  • Hardee_kh93

    plz ans me

  • Bhagyesh

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

  • Shimul

    #include
    #include

    int main(void) {
     int i,x,j;
     
     printf(“Enter the size = “);
     scanf(“%d”,&x);
     printf(“nn”);
     
     
     printf(“1n”);
      for (j = 2; j <=x; j++) {
        printf("1%dn",j);

       }
     getch();
     return 0;
    }

  • Shimul

    #include
    #include

    int main(){
        int a,i,j;
        printf(“Enter the size number = “);
        scanf(“%d”,&a);
        printf(“n”);
        
        for(i=a;i>=1;i–){
                          printf(“%d %dn”,i,i);
                          }
        printf(“0n”);
        for(j=1;j<=a;j++){
                          printf("%d %dn",j,j);
                          }
        getch();
    }
                          

  • Shimul

    #include
    #include

    int main()
    {
      int i,a,j,b=1;
      printf(“Enter a Size = “);
      scanf(“%d”,&a);
      for(i=1;i<=a;i++)
        {
          for(j=1;j<=i;j++)
              {
                printf("%d", b);
                b++;
              }
          printf("n");
        }
     

        getch();
    }
        

  • Shimul

    #include
    #include

    int main()
    {
      int i,a,j,b=1;
      printf(“Enter a Size = “);
      scanf(“%d”,&a);
      for(i=1;i<=a;i++)
        {
          for(j=1;j<=i;j++)
              {
                printf("%d", b);
                b++;
              }
          printf("n");
        }
     

        getch();
    }
       

  • Samvedna

    how to print 
    0
    1 1
    2 2 2
    0 0 0 0
    1  1  1  1  1
    2 2  2  2  2  2
    .   .    .   .   .   .  .

  • guest

    simple c++    program for the below pattern pls

         1
       1 2 1
    1 2 3 2 1
       1 2 1
          1

  • SHREE

    CAN U GIVE THE CODING FOR THE ABOVE PATTERN PLEASE URGENT

  • Shivanshu Gupta

    5 4 3 2 1
    5 4 3 2
    5 4 3
    5 4
    5

  • nikita

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

  • Tasheo

    program which will ask the user for a two numbers (How wide and how high) and then generate an XO pattern.
    like if user enters…3 and 4

    XOX
    OXO
    XOX
    OXO

  • Neethu

    #include
    int main() {
          /* c taken for columns */
          int i, j, c = 9, m, k;
          for (i = 1; i <= 5; i++) {
                /* k is used for spaces */
                for (k = 1; k <= c; k++) {
                      printf(" ");
                }
                for (j = 1; j 0; m–) {
                      /* %2d ensures that the number
                       * is printed in two spaces
                       * for alignment */
                      printf(“%2d”, m);
                }
                printf(“n”);
                /* c is decremented by 2 */
                c = c – 2;
          }
          return 0;
    }

  • Ram Airan

    #include
    void main()
    {
    int num=1, rows;
    printf(“Enter number of rows: “);
    scanf(“%d”, &rows);
    do
    {
    printf(“%dn”,num);
    num*=11;
    }while(rows>0);
    getch();
    }

  • Rachit Agrawal

    #include
    void main()
    {
     int i,j,k, num, sum;
     clrscr();
     printf(“Plz enter number of rows : “);
     scanf(“%d”, &num);
     for(i=1,k=1,sum=0;i<=num;i++)
     {
      for(j=1;j<=i;j++,k++)
      {
       printf("%d ",k);
       sum+=k;
      }
      k=sum;
     }
     getch();
    }

  • Anonymous

    plz give me the code of following
                                             1                                                                     1
                                          2    2                                                             2    2
                                     3     3     3                                                      3    3     3
                                  4    4     4      4                                              4    4     4    4

  • Crazy145_romi

    give me source code for this pattern
    1234  4321
    12 3      321
    12           21
    1              1

  • Mohdyusufadill

    pls give me source code for this pattern
    1234  4321
    12 3      321
    12           21
    1              1

  • SherylC.

    public class (insert file name here) <– no parenthesis… but you knew that already ;) {

    public static void main( String[] args ) {

    for( int x=1; x<=4; x++ ) {
    for( int y=1; y<=x; y++ ) {
    System.out.print( "*" );
    }
    System.out.println( "" );
    }
    }
    }

  • Bansalshubham257

    give the coding of
              *
           *    *
        *     *    *
    *     *      *    *

  • Ajay

    hello!

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

  • trushar

    if n=3 & ch=A

    B
    C E
    H M U
    H C
    K

    do this pattern using fibo ……

  • Tarakaramji

    123454321
     1234321
      12321
       121
        1
       121
      12321
     1234321
    123454321
    Kindly give me the code for this??

  • Naveen1728

    main()
    {
    int i,j,n,k;
    clrscr();
    for(i=1;i<=4;i++)
    {
    for(j=1;j<=4-i;j++)
    printf(" ");
    for(k=1;k<=i;k++)
    printf("%d",i);
    printf("n");
    }
    getch();
    }

  • Ridzi0207

    can u plz give me the code for
    *******
    *******
    *   ***  *
    *      *    *
    *    ***  *
    *******
    *******
    plz…its very urgent

  • Ndevnani55

    PLEASE GET ME THE CODE THIS PROBLEM
    4   3    2    1
       3    2    1
           2    1
               1

Previous post:

Next post: