0% found this document useful (0 votes)
31 views2 pages

Factorial: 3. Triangulo de Pascal

The document contains code for 3 different programs: 1. A factorial program that calculates the factorial of a given integer recursively. 2. A Fibonacci program that calculates the nth Fibonacci number recursively. 3. A Pascal's triangle program that generates a Pascal's triangle of a given size input by the user.

Uploaded by

Angie Bernate
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views2 pages

Factorial: 3. Triangulo de Pascal

The document contains code for 3 different programs: 1. A factorial program that calculates the factorial of a given integer recursively. 2. A Fibonacci program that calculates the nth Fibonacci number recursively. 3. A Pascal's triangle program that generates a Pascal's triangle of a given size input by the user.

Uploaded by

Angie Bernate
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

1.

factorial

Public class factorial {

Public static long s (int n)


{if (n==1)
return 1;
else
return (n-1)+n;
}
}

2.fibonacci

Public class fibonacci {

public static long fibo (int n, int i, int j, int x, int y)


{
if (n<=1)
returnx+y;
else
return fibo(n-1,y,x+y, x, y);
}
Public static long fib (int n)
{
return fibo(n,0,1, n, n);}
}

3. Triangulo de pascal
importjava.util.Scanner;

public class triangulo_pascal {

public static void main(String[] args) {

Scanner leer = new Scanner(System.in);


System.out.println("Hasta donde desea hacerlo: ");
intlimite = leer.nextInt();

System.out.println("");
int[] a = newint[1];

for (inti = 1; i<= limite; i++) {


int[] x = newint[i];
for (int j = 0; j <i; j++) {
if (j == 0 || j == (i - 1)) {
x[j] = 1;
}
else
{
x[j] = a[j] + a[j - 1];
}
System.out.print(x[j] + " ");
}
a = x;
System.out.println();
}
}
}

3. decimal a binario
import java.io.*;
public class DecBin {
/**

* Decimal a binario! a mimanera! xD


*/
Public static void main(String[] args)throws IOException {
BufferedReader L = new BufferedReader(new
InputStreamReader(System.in));
int Decimal,R, x = 0;
String Binario = "";

Decimal=Integer.parseInt(L.readLine());

R = Decimal%2;
if (R == 1){

while (Decimal > 1){


Decimal /= 2;
x = Decimal%2;
Binario = (x+Binario +"");
}
}
else{

while (Decimal > 0){


Decimal /= 2;
x = Decimal%2;
Binario = (x+Binario +"");
}
}

System.out.println(Binario +x);
}

You might also like