5.15.2016

Diagonal Number Pattern In C

Q. Write a C program to make a diagonal number pattern as following design:

         1
        2
       3
      4
     5

Ans.

/* c program source code for diagonal number pattern*/

#include<stdio.h>
int main()
{
  int num,r,c,sp;
  printf("Enter total no. rows : "); 
  scanf("%d", &num);
  for(r=1; r<=num; r++)
  {
    for(sp=r; sp<num; sp++)
        printf(" ");
    printf(" %d\n",r);
  }
  getch();
  return 0;
}

/***************************************************
The output of above program would be:
***************************************************/
Output of diagonal Number Pattern In C Program
Figure: Screen shot for Diagonal Number Pattern In C Output

You might also like to read:

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


No comments:

Post a Comment