Q. Write a C program to print the following number structure:
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
6 6 6 6 6 6
Ans.
/*c program for print the following number triangle*/
#include<stdio.h>
#include<conio.h>
int main()
{
int r,c,sp,n=6;
for(r=1; r<=6; r++)
{
for(sp=1; sp<=n; sp++)
printf(" ");
for(c=1; c<=r; c++)
{
printf("%d",r);
printf(" ");
}
printf("\n");
n=n-1;
}
getch();
return 0;
}
/************Output************/
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
6 6 6 6 6 6
Ans.
/*c program for print the following number triangle*/
#include<stdio.h>
#include<conio.h>
int main()
{
int r,c,sp,n=6;
for(r=1; r<=6; r++)
{
for(sp=1; sp<=n; sp++)
printf(" ");
for(c=1; c<=r; c++)
{
printf("%d",r);
printf(" ");
}
printf("\n");
n=n-1;
}
getch();
return 0;
}
/************Output************/
Screen shot for number triangle C program |
No comments:
Post a Comment