Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions FloydsTriangle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import java.util.Scanner;
/*
ques: Floys triange?
"Floyd's Triangle," which is a right-angled triangular array of natural numbers.
In this triangle, each row contains consecutive natural numbers, starting from 1.

1
2 3
4 5 6

*/

public class FloydsTriangle {
public static void main(String[] args) {
System.out.print("Enter the number of row:");
Scanner sc = new Scanner(System.in);
int n=sc.nextInt();

int x=1;
//outer loop
for(int i=1; i<=n; i++){
for(int j=1; j<=i; j++){
System.out.print(x+" ");
x++;
}
System.out.println();
}

}
}

/*
OUTPUT:

Enter the number of row:5
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15

*/