Q. Write a C program to print the following Increased Number Triangle as:
5
45
345
2345
12345
Ans.
/*c program for increased number triangle*/
#include<stdio.h>
int main()
{
int num,r,n,sp;
printf("Enter no. of rows : ");
scanf("%d", &num);
for(r=1; r<=num; r++)
{
for(sp=num-r; sp>=1; sp--)
printf(" ");
for(n=num-r+1; n<=num; n++)
printf("%d",n);
printf("\n");
}
getch();
return 0;
}
The output of above program would be:
5
45
345
2345
12345
Ans.
/*c program for increased number triangle*/
#include<stdio.h>
int main()
{
int num,r,n,sp;
printf("Enter no. of rows : ");
scanf("%d", &num);
for(r=1; r<=num; r++)
{
for(sp=num-r; sp>=1; sp--)
printf(" ");
for(n=num-r+1; n<=num; n++)
printf("%d",n);
printf("\n");
}
getch();
return 0;
}
The output of above program would be:
Figure: Screen-shot for Increased Number Triangle C program |
Comments
Post a Comment