9.01.2013

Half-Square Number Triangle

Q. Write a C program to print the following half-square number triangle C program as : 

543212345
 4321234
  32123
   212
    1

Ans.

/*c program for half-square number triangle*/
#include<stdio.h>
int main()
{
 int num,r,c,n,sp,p;

 printf("Enter any number : ");
 scanf("%d", &num);
 for(r=1,n=num; r<=num; r++,n--)
 {
   for(sp=r; sp>1; sp--)
      printf(" ");
   for(c=r,p=n; c<=num; c++,p--)
      printf("%d",p);
   for(c=num-r,p=2; c>=1; c--,p++)
      printf("%d",p);
   printf("\n");
 }
 getch();
 return 0;
}



/******************************************

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


Output of Half-Square Number Triangle C program
Figure :  Screen shot for Half-Square Number Triangle C program

You might also like to read:
  1. Big list of 98+ C pyramid programs list
  2. Latest user asking pyramid programs list

2 comments:

  1. Can you do this for letters?

    DCBABCD
    _CBABC_
    __BAB___
    ___A____

    ReplyDelete
    Replies
    1. Your Required T Shape Character pattern C program at:

      http://cprogrammingcodes.blogspot.com/2016/01/t-shape-character-pyramid.html

      Delete