1 4 6 4 1 ].
Q14.
Write a C program to display the Floyd triangle.
[Hint:
Let us write its algorithm first:
1. Initialize a=1.
2. Read
the number of rows,
row.
3. Initialize i=0.
4. Repeat through step 12 until i is less than
row.
5. Initialize j=0.
6. Repeat through step 10 until j is less than or equal to i.
7. Print a.
8. If a is less than 10, print “ ” else print “ ”.
9. a=a+1
10. j=j+1
11. Move to the next line.
12. i=i+1
13. Stop and exit.
The program is as follows:
void main( )
{
int a=1,i, j, row;
printf(“Enter the number of rows:”);
scanf(“%d”, & row);
printf(“\n”);
for(i=0;i
|
{
for(j=0;j<=i;j++)
{
if(a<10)
printf(“%d\t”, a);
else
printf(“%d\t”, a);
a++;
}
printf(“\n”);
}
}
}
Do'stlaringiz bilan baham: