Showing posts with label source code for number rectangle pyramid. Show all posts
Showing posts with label source code for number rectangle pyramid. Show all posts

Sunday, 15 July 2012

Number rectangle structure

Q. Write a C program to display the following number structure:


1234554321
1234__4321
123____321
12______21
1________1


Ans.


/* c program for number rectangle or number pyramid*/
#include<stdio.h>
#include<conio.h>
int main()
{
 int num,c,sp,r=1;
 printf("Enter loop repeat number(rows): ");
 scanf("%d",&num);
 printf("\n");
 for(; num>=1; num--,r++)
 {
  for(c=1; c<=num; c++)
     printf("%d",c);
  for(sp=r; sp>1; sp--)
     printf("_");
  for(sp=r; sp>1; sp--)
     printf("_");
  for(c=num; c>=1; c--)
     printf("%d",c);
  printf("\n");
 }
 getch();
 return 0;
}


/***************Output****************/
Output of number structure pyramid C program
Screen-shot for number pyramid structure of C program