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

How to Make a Continuous Diagonal Number Pyramid C program

Q. Write a C program to print the following continues odd reverse number pyramid pattern as:

 1
 6 2
10 7 3
13 11 8 4
15 14 12 9 5

Ans.

Before we start to write the code for above continuous diagonal number pyramid C program, let's focus on below image for better understand the structure of pattern.

How to make a Continuous Diagonal Number Pyramid C Program
Figure: How to make a Continuous Diagonal Number Pyramid C Program


/*c program for continuous diagonal number pyramid pattern*/
#include<stdio.h>
int main()
{

 int num,r,c,m,n,z,a;
 printf("Enter No. of Rows : ");
 scanf("%d", &num);
 z=num;
 n=1;
 for(r=1; r<=num; r++, n=n+7-r, z--)
 {
   m=n;
   a=num-r;
   for(c=1; c<=r; c++, m=m-a)
   {
      printf(" %d ", m);
      a++;
   }
   printf("\n");
 }
 getch();
 return 0;
}

/*************************************************************
The output of above Continuous Diagonal number pyramid pattern C program
***************************************************************/

Output for Continuous Diagonal Number Pyramid C Program
Figure: Screen shot for output of Continuous Diagonal Number Pyramid C Program


You might also like:





0 komentar:

Post a Comment

How to Make a Continuous Diagonal Number Pyramid C program