2. Program to print Floyd's Triangle?
1
2 3
4 5 6
7 8 9 10
Algorithm
Step 1:Start
Step 2:Declare variables i,j,count=1,lim.
Step 3:Input the Limit of the Floids Triangle.
Step 4:Read the Limit.
Step 5:Initialize i=0
Step 6:while(i<=lim) repeat steps 6.1 to 6.5
6.1)Initialize j=0
6.2)while(j<i)
a)Print the count,%3d, 3 denotes space between two numbers.
b)Increment count by 1.
c)Increment j by 1.
6.3)End while.
6.4)Print new line.
6.5)Increment i by 1.
Step 7:End while
Step 8:Stop.
Program
#include <stdio.h>
#include <conio.h>
void main()
{
int i,j,count=1,lim;
clrscr();
printf("Enter the limit :");
scanf("%d",&lim);
for(i=0;i<=lim;i++)
{
for(j=0;j<i,j++)
{
printf("%3d",count);
count++;
}
printf("\n");
}
getch();
}
Output
Enter the limit :4
1
2 3
4 5 6
7 8 9 10
No comments:
Post a Comment