7.15.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

7 comments:

  1. plz tell me about the algorithm formed in this pyramid

    ReplyDelete
    Replies
    1. Algorithm for above number pyramid structure at:

      http://cprogrammingcodes.blogspot.in/2012/10/algorithm-for-number-pyramid.html

      Delete
  2. thanx sir,you are great

    ReplyDelete
  3. how to make this:
    ABCDEFGFEDCBA
    ABCDEF_FEDCBA
    ABCDE___EDCBA
    ABCD_____DCBA
    ABC________CBA
    AB___________BA
    A_____________A

    PLEASE HELP

    ReplyDelete
    Replies
    1. @Bhwanesh Dipu,

      Your required character pattern source code at:
      http://cprogrammingcodes.blogspot.in/2013/12/character-rectangle-structure.html

      Delete
  4. //Instead of 6 you can take any value
    public class Question2
    {
    public static void main(String[] args)throws java.io.IOException
    {
    int c;
    for(int num=6;num>=1;num--)
    {
    for(c=1;c<=num;c++)
    {
    System.out.print(c);
    }
    //for space
    while(c<=6)
    {
    System.out.print("_"+"_");
    c++;
    }
    for(c=num;c>=1;c--)
    {
    System.out.print(c);
    }

    System.out.println();
    }
    }
    }

    ReplyDelete
  5. how to get this:
    1234567
    123 567
    12 67
    1 7
    12 67
    123 567
    1234567

    ReplyDelete