Q. Write a C program to print the following number triangle:
1
12
123
1234
12345
1234
123
12
1
Ans.
/*c program for print the number pyramid as specific given design*/
#include<stdio.h>
#include<conio.h>
int main()
{
int r,c,n;
printf("Enter loop repeat number(rows): ");
scanf("%d", &n);
for(r=1; r<=n; r++)
{
for(c=1; c<=r; c++)
printf("%d",c);
printf("\n");
}
for(r=n; r>1; r--,n--)
{
for(c=1; c<n; c++)
printf("%d",c);
printf("\n");
}
getch();
return 0;
}
/**************Output**************/
1
12
123
1234
12345
1234
123
12
1
Ans.
/*c program for print the number pyramid as specific given design*/
#include<stdio.h>
#include<conio.h>
int main()
{
int r,c,n;
printf("Enter loop repeat number(rows): ");
scanf("%d", &n);
for(r=1; r<=n; r++)
{
for(c=1; c<=r; c++)
printf("%d",c);
printf("\n");
}
for(r=n; r>1; r--,n--)
{
for(c=1; c<n; c++)
printf("%d",c);
printf("\n");
}
getch();
return 0;
}
/**************Output**************/
Screen shot for number triangle C program |
No comments:
Post a Comment