Please Help me in Floyd's triangle

Amit Kumar Saha's Avatar, Join Date: Aug 2008
Go4Expert Member
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..
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
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++;
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
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++
balaje26's Avatar
Newbie Member
Floyds triangle full program...?
Amit Kumar Saha's Avatar, Join Date: Aug 2008
Go4Expert Member
yes,
Many thanks for showing interest.
Amit Kumar Saha's Avatar, Join Date: Aug 2008
Go4Expert Member
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.
oogabooga's Avatar
Ambitious contributor
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");
  }
balaje26's Avatar
Newbie Member
how to learn c easy
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
Get someone else to do it. Programming is HARD.
aadilprabhakar's Avatar, Join Date: Nov 2008
Newbie Member
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