Floyd's triangle lists the natural numbers in a right triangle aligned to the left where
the first row is just 1
successive rows start towards the left with the next number followed by successive naturals listing one more number than the line above.
The first few lines of a Floyd triangle looks like this:
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
Program
#include<stdio.h>
#include<stdio.h>
void main()
{
int i,j,n,num;
clrscr();
printf("How many lines to print");
scanf("%d",&n);
num=1;
for(i=0;i<n;i++)
{
for(j=0;j<=i;j++)
{
printf("\t%d",num++);
}
printf("\n");
}
getch();
}
Output:
How many lines to print
4
1
2 3
4 5 6
7 8 9 10
the first row is just 1
successive rows start towards the left with the next number followed by successive naturals listing one more number than the line above.
The first few lines of a Floyd triangle looks like this:
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
Program
#include<stdio.h>
#include<stdio.h>
void main()
{
int i,j,n,num;
clrscr();
printf("How many lines to print");
scanf("%d",&n);
num=1;
for(i=0;i<n;i++)
{
for(j=0;j<=i;j++)
{
printf("\t%d",num++);
}
printf("\n");
}
getch();
}
Output:
How many lines to print
4
1
2 3
4 5 6
7 8 9 10
Pankaj Gaikar is a
professional blogger
from Pune, India who writes on Technology, Android,
Gadgets, social media and latest tech updates at
Punk Tech
,
Being Android
&
Shake The Tech
. Email me
HERE
0 comments :
Post a Comment