/**
* @(#)PascalTriangle.java
*
*
* @author -> Anant Mahale
* @version 1.00 2013/7/3
*/
import java.io.*;
class PascalTriangle
{
public static void main(String []args)
{
try
{
DataInputStream cin=new DataInputStream(System.in);
System.out.print("Enter number of rows for pascal triangle:");
int n = Integer.parseInt(cin.readLine());
for (int y = 0; y < n; y++)
{
int c = 1;
for(int q = 0; q < n - y; q++)
{
System.out.print(" ");
}
for(int x = 0; x <= y; x++)
{
System.out.print(" ");
System.out.print(c); // 3 digits
System.out.print(" ");
c = c * (y - x) / (x + 1);
}
System.out.println();
System.out.println();
}
System.out.println();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
* @(#)PascalTriangle.java
*
*
* @author -> Anant Mahale
* @version 1.00 2013/7/3
*/
import java.io.*;
class PascalTriangle
{
public static void main(String []args)
{
try
{
DataInputStream cin=new DataInputStream(System.in);
System.out.print("Enter number of rows for pascal triangle:");
int n = Integer.parseInt(cin.readLine());
for (int y = 0; y < n; y++)
{
int c = 1;
for(int q = 0; q < n - y; q++)
{
System.out.print(" ");
}
for(int x = 0; x <= y; x++)
{
System.out.print(" ");
System.out.print(c); // 3 digits
System.out.print(" ");
c = c * (y - x) / (x + 1);
}
System.out.println();
System.out.println();
}
System.out.println();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
No comments:
Post a Comment