Shown below is a Floyd's triangle.
1
2 3
4 5 6
7 8 9 10
11.........15
.
.
79...................91
Write a program to print this triangle.
#include <stdio.h>
void main()
{
int i,j=1,n=1,count=1;
clrscr();
printf("Enter n value:");
scanf("%d",&n);
while(j
{
for(i=1;i<=count;i++)
{
if(j-1==n)
break;
printf("%5d",j++);
if(i==count)
printf("\n");
}
count=i;
i=1;
}
getch();
}
1
2 3
4 5 6
7 8 9 10
11.........15
.
.
79...................91
Write a program to print this triangle.
#include <stdio.h>
void main()
{
int i,j=1,n=1,count=1;
clrscr();
printf("Enter n value:");
scanf("%d",&n);
while(j
{
for(i=1;i<=count;i++)
{
if(j-1==n)
break;
printf("%5d",j++);
if(i==count)
printf("\n");
}
count=i;
i=1;
}
getch();
}
No comments:
Post a Comment