Q. Write a C program to print the following number pyramid.
123456654321
1234554321
12344321
123321
1221
11
Ans.
/*c program for print the number pyramid*/
#include<stdio.h>
#include<conio.h>
int main()
{
int num,i,j,n,r;
printf("Enter number of rows: ");
scanf("%d", &num);
n = num;
printf("\n");
for(r=1; r<=num; r++,n--)
{
for(i=1; i<=n; i++)
printf("%d",i);
for(j=n; j>=1; j--)
printf("%d",j);
printf("\n");
}
getch();
return 0;
}
Related Programs:
Q. Write a C program to print the following character pyramid.
ABCDEFFEDCBA
ABCDEEDCBA
ABCDDCBA
ABCCBA
ABBA
AA
You might also like:
or
Q. write a C program to print the following number triangle.123456654321
1234554321
12344321
123321
1221
11
Ans.
/*c program for print the number pyramid*/
#include<stdio.h>
#include<conio.h>
int main()
{
int num,i,j,n,r;
printf("Enter number of rows: ");
scanf("%d", &num);
n = num;
printf("\n");
for(r=1; r<=num; r++,n--)
{
for(i=1; i<=n; i++)
printf("%d",i);
for(j=n; j>=1; j--)
printf("%d",j);
printf("\n");
}
getch();
return 0;
}
/****************************************************
The output of above program would be:
*****************************************************/
Figure: Screen shot for number pyramid C program |
Related Programs:
Q. Write a C program to print the following character pyramid.
ABCDEFFEDCBA
ABCDEEDCBA
ABCDDCBA
ABCCBA
ABBA
AA
You might also like:
#include
ReplyDeleteint main()
{
int i,j,r,n;
printf("Enter the no. of rows: ");
scanf("%d",&n);
printf("The required triangle is:\n\n");
for(r=0;r0;r++,n--)
{
for(i=0;i0;j--)
printf("%c",j+64);
printf("\n");
}
return 0;
}
#include
ReplyDeleteint main()
{
int i,j,r,n;
printf("Enter the no. of rows: ");
scanf("%d",&n);
printf("The required triangle is:\n\n");
for(r=0;r0;r++,n--)
{
for(i=0;i0;j--)
printf("%c",j+64);
printf("\n");
}
return 0;
}
#include
ReplyDeleteint main()
{
int i,j,r,n;
printf("Enter the no. of rows: ");
scanf("%d",&n);
printf("The required triangle is:\n\n");
for(r=0;r0;r++,n--)
{
for(i=0;i0;j--)
printf("%c",j+64);
printf("\n");
}
return 0;
}
#include
ReplyDeleteint main()
{
int i,j,r,n;
printf("Enter the no. of rows: ");
scanf("%d",&n);
printf("The required triangle is:\n\n");
for(r=0;r0;r++,n--)
{
for(i=0;i0;j--)
printf("%c",j+64);
printf("\n");
}
return 0;
}
#include
ReplyDeleteint main()
{
int i,j,r,n;
printf("Enter the no. of rows: ");
scanf("%d",&n);
printf("The required triangle is:\n\n");
for(r=0;r0;r++,n--)
{
for(i=0;i0;j--)
printf("%c",j+64);
printf("\n");
}
return 0;
}