9.10.2015

Number Pattern In C

Q. Write the following number pattern program in C language as:

    123454321
    1234321
    12321
    121
    1

Ans.

Before we start to write the source code of above number pattern program, if you look carefully on above pattern, there are 2 number pattern shows as:


    123454321
    1234321
    12321
    121
    1

So just make above 2 number pattern and merge them, that's it, done! cheers!!
let's start the coding in C.

/*c program for number pattern*/
#include<stdio.h>
int main()
{
  int num,r,c,n;
  printf("Enter any number : ");
  scanf("%d", &num);
  n=num;
  for(r=1; r<=num; r++,n--)
  {
     for(c=1; c<=n; c++)
         printf("%d", c);
     for(c=n-1; c>=1; c--)
         printf("%d", c);
     printf("\n");
  }
  getch();
  return 0;
}


/****************************************************************
The output of above program would be:
******************************************************************/


Output of Number Pattern In C Programming Language
Figure: Screen shot of Number Pattern In C Programming Language

You might also like:
  1. Character pattern in C
  2. Big list of 98+ C pyramid programs
  3. Latest user asking pyramid program list

2 comments: