Notes: As Digit Limit is 10^60 so it is Big Integer Calculation. As I am comfortable With Java BigInteger Than C++ So I Prefer Java. There is no space after last element of every row. After Every Line There Is New Line. So After Last Line There is a new line.
import java.util.*;
import java.math.*;
public class Main{
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int i,j;
BigInteger[][] a=new BigInteger[206][206];
for(i=0;i<a.length;i++)
{
for(j=0;j<a.length;j++)
{
a[i][j]=BigInteger.valueOf(0);
}
}
for(i=1;i<a.length;i++)
{
a[i][1]=BigInteger.valueOf(1);
}
for(i=2;i<a.length;i++)
{
for(j=2;j<a.length;j++)
{
a[i][j]=a[i-1][j].add(a[i-1][j-1]);
}
}
for(i=1;i<a.length;i++)
{
for(j=1;j<a.length;j++)
{
if(!(a[i][j].compareTo(BigInteger.ZERO)==0))
{
if(j!=1 && a[i][j].compareTo(BigInteger.ONE)==0)
{
System.out.print("1"); //Avoiding Space After Last Element
}
else if(i==1 && j==1)
{
System.out.print(a[1][1]); //Avoiding Space As 1st 1 is in a[1][1]
}
else
{
System.out.print(a[i][j]+" ");
}
}
}
System.out.println();
}
}
}
0 comments:
Post a Comment