Please Help me in Floyd's triangle

Go4Expert Member
23Aug2008,08:27   #1
Amit Kumar Saha's Avatar
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.

Thanking you in advance...

Amit

Last edited by Amit Kumar Saha; 23Aug2008 at 08:35..
Mentor
26Aug2008,03:45   #2
xpi0t0s's Avatar
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++;
Mentor
26Aug2008,12:25   #3
xpi0t0s's Avatar
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++
Newbie Member
16Sep2008,21:43   #4
balaje26's Avatar
Floyds triangle full program...?
Go4Expert Member
17Sep2008,01:11   #5
Amit Kumar Saha's Avatar
yes,
Many thanks for showing interest.
Go4Expert Member
17Sep2008,01:22   #6
Amit Kumar Saha's Avatar
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.
Ambitious contributor
17Sep2008,06:12   #7
oogabooga's Avatar
xpi0t0s has already answered your question.
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");
  }
Newbie Member
17Sep2008,20:34   #8
balaje26's Avatar
how to learn c easy
Mentor
17Sep2008,22:08   #9
xpi0t0s's Avatar
Get someone else to do it. Programming is HARD.
Newbie Member
18Nov2008,11:54   #10
aadilprabhakar's Avatar
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 shabbir; 18Nov2008 at 16:26.. Reason: Code block