Floyd Triangle
Problem to form the Floyd Triangle pattern in given number.
Example-1:
Input : n = 4 Output : 1 2 3 4 5 6 7 8 9 10
Example-2:
Input : n = 5 Output : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Solution
public class Main { public static void main(String [] args) { int n = 4; int a = 1; for(int i = 0; i <n;i++) { for (int j = 0; j <= i; j++) { System.out.print(a+" "); a++; } System.out.println(""); } } }
n = 4 a = 1 for i in range(1,n+1): for j in range(1,i+1): print(a,end=" ") a += 1 print()
Output
1 2 3 4 5 6 7 8 9 10