# Floyd's triangle

Discussion in 'C' started by Amit Kumar Saha, Aug 23, 2008.

1. ### Amit Kumar SahaNew Member

Joined:
Aug 1, 2008
Messages:
14
0
Trophy Points:
0

Friends,

How can I control the increment of variable in floyd triangle. And I how should I initialize?

another optional problem what is cycle length between and including two int number.

Amit
:nice:

Last edited: Aug 23, 2008
2. ### xpi0t0sMentor

Joined:
Aug 6, 2004
Messages:
3,012
203
Trophy Points:
63
Occupation:
Senior Support Engineer
Location:
England
I'm not really sure what you mean. I'd use three variables for that, one containing the current number, one containing the number of numbers in the current line, and the third would be a loop from 0 to the second. Probably something like:
Code:
```int i=1, j=1;
for (k=0; k<j; k++)
printf("%d ",i++);
printf("\n");
j++;
```

3. ### xpi0t0sMentor

Joined:
Aug 6, 2004
Messages:
3,012
203
Trophy Points:
63
Occupation:
Senior Support Engineer
Location:
England
I'm not really sure what you mean. I'd use three variables for that, one containing the current number, one containing the number of numbers in the current line, and the third would be a loop from 0 to the second (plus some sort of bailout condition). Probably something along the following lines:
Code:
```int i=1, j=1
for k=0..j
printf(i++)
printf("\n")
j++
```

4. ### balaje26New Member

Joined:
Sep 10, 2008
Messages:
2
0
Trophy Points:
0
Floyds triangle full program...?

5. ### Amit Kumar SahaNew Member

Joined:
Aug 1, 2008
Messages:
14
0
Trophy Points:
0
yes,
Many thanks for showing interest.

6. ### Amit Kumar SahaNew Member

Joined:
Aug 1, 2008
Messages:
14
0
Trophy Points:
0
brothers,

plz don't mind I have forgot how to start a new thread. Plz pardon me for this.

help me in this problem first.

7. ### oogaboogaNew Member

Joined:
Jan 9, 2008
Messages:
115
11
Trophy Points:
0
To recap, something like this:
Code:
```  int column, line, n = 1;
for (line = 0; line < number_of_lines; ++line) {
for (column = 0; column <= line; ++column)
printf ("%3d ", n++);
printf ("\n");
}
```

8. ### balaje26New Member

Joined:
Sep 10, 2008
Messages:
2
0
Trophy Points:
0
how to learn c easy

9. ### xpi0t0sMentor

Joined:
Aug 6, 2004
Messages:
3,012
203
Trophy Points:
63
Occupation:
Senior Support Engineer
Location:
England
Get someone else to do it. Programming is HARD.

Joined:
Nov 18, 2008
Messages:
2
0
Trophy Points:
0
Location:
India
Code:
```import java.util.*;
import java.math.*;
import java.io.*;

public class pyramid{

public static void main(String argsp[]){
int i=1,j;
int num = 1;
while(num<=91){
for(j=1; j<=i; j++){
System.out.print (num + " ");
num++;

}
i++;
System.out.print("\n");
}

}
}```
Heres a solution to Floyds Triangle in JAVA

Last edited by a moderator: Nov 18, 2008
11. ### back from retirementNew Member

Joined:
Nov 9, 2008
Messages:
72
1
Trophy Points:
0
Occupation:
Student, UG 1st Yr., Jadavpur University
Location:
Uttarpara, West Bengal, India
Have a look at my argument...it's similar, except for the display is in a equilateral triangular fashion....
Code:
```#include<stdio.h>
#include<conio.h>

#define m 4

void main()
{
int i,j,c,n=1,p=m;
for(i=0;i<m;i++)
{
for(c=p;c>=0;c--)
{
printf(" ");
}
for(j=0;j<=i;j++)
{
printf("%d ", n);
n++;
}
printf("\n");
p--;
}
getch();
}
```
Cheers....