Pages

Saturday

Program to Print Number Pattern in C | Pattern 1

Here is a C Program to print number pattern like 1 232 34543 4567654 567898765 and so on with output and explanation. This program uses C concepts like For Loop in C, Auto Incrementing Operator ++ and Nested For Loops.

.
# include <stdio.h>

int main(){
  int n, k;
  printf("Enter up to how many times you want to print the pattern: ");
  scanf("%d", &n);
  printf("\n");
  for(int i = 1;i <= n;i++){
    k = i;
    for(int j = 1;j <= i;j++){
      printf("%d", k++);
    }
    for(int j = k - 1;j > i;j--){
      printf("%d", j - 1);
    }
    printf("\n");
  }
  for(int i = n - 1;i > 0;i--){
    k = i;
    for(int j = 1;j <= i;j++){
      printf("%d", k++);
    }
    for(int j = k - 1;j > i;j--){
      printf("%d", j - 1);
    }
    printf("\n");
  } 
  return 0;
}


Output of above program

1
232
34543
4567654
567898765
4567654
34543
232
1

1 comment:

  1. Ni Hau,


    11/10!! Your blog is such a complete read. I like your approach with C Programming Tutorial . Clearly, you wrote it to make learning a cake walk for me.

    I want to make a dynamic array of char* returned by a function. I need to save the name of files contained inside a folder to a dynamic array of char*.
    My IDE is dev-c++, my favorite, my language is C.


    Awesome! Thanks for putting this all in one place. Very useful!


    Thanks a heaps,

    ReplyDelete