PROGRAM TO PRINT FLOYD'S TRIANGLE
THE FOLLOWING PROGRAM SEGMENT SHOWS HOW TO PRINT THE FLOYD'S TRIANGLE
import java.util.*;
class FloydTriangle
{
public static void main (String args[])
{
Scanner ob = new Scanner (System.in);
int n, num = 1, c , d;
System.out.println("enter the number of rows of floyd's triangle");
n = ob.nextInt();
System.out.println("Floyd's Triangle");
for(c = 1;c <= n; c++)
{
for(d = 1; d <= c ; d++)
{
System.out.print(num + "\t");
num++;
}
System.out.println();
}
}
}
Comments
Post a Comment