Silahkan Melihat Tutorial di website kami dengan nyaman ENJOY YOUR LIFE ☕

3 Nested Number Pattern C Program

Q. Write a C program to make the following number pattern triangle program as:

     10 9 8 7 6 5 4 3 2 1 0
     10 9 8 7 5 3 2 1 0
     10 9 8 5 2 1 0
     10 9 5 1 0
     10 5 0
     5    

Ans.

Before you start to write down the source code of above number pattern program, carefully look the number pattern and divide it sub pattern as following:

     10 9 8 7 6 5 4 3 2 1 0
     10 9 8 7 5 3 2 1 0
     10 9 8 5 2 1 0
     10 9 5 1 0
     10 5 0
     5 


Now it is easy to understandable, there are 3 types number pattern triangle program. 

So first of all write the code for first number pattern program, after that make second number pattern program and lastly write the code 3rd number pattern program.
Now merge them. You are done. Cheers !!

Let's start the coding of above C program.

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


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


Output of 3 Nested Number Pattern C Program
Figure: Screen shot of 3 Nested Number Pattern C Program 

You might also like to read:

  1. Big list of 98+ C pyramid programs
  2. Latest user asking pyramid program list




0 komentar:

Post a Comment

3 Nested Number Pattern C Program