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****************/
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****************/
Screen-shot for number pyramid structure of C program |
plz tell me about the algorithm formed in this pyramid
ReplyDeleteAlgorithm for above number pyramid structure at:
Deletehttp://cprogrammingcodes.blogspot.in/2012/10/algorithm-for-number-pyramid.html
thanx sir,you are great
ReplyDeletehow to make this:
ReplyDeleteABCDEFGFEDCBA
ABCDEF_FEDCBA
ABCDE___EDCBA
ABCD_____DCBA
ABC________CBA
AB___________BA
A_____________A
PLEASE HELP
@Bhwanesh Dipu,
DeleteYour required character pattern source code at:
http://cprogrammingcodes.blogspot.in/2013/12/character-rectangle-structure.html
//Instead of 6 you can take any value
ReplyDeletepublic 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();
}
}
}
how to get this:
ReplyDelete1234567
123 567
12 67
1 7
12 67
123 567
1234567