Skip to content

Instantly share code, notes, and snippets.

@jimywork
Last active August 22, 2017 16:08
Show Gist options
  • Save jimywork/7fbf31a18c2c229d8a19ca571285ee23 to your computer and use it in GitHub Desktop.
Save jimywork/7fbf31a18c2c229d8a19ca571285ee23 to your computer and use it in GitHub Desktop.
Exercício de Repeticao Java
/* Faça um programa que leia um valor N inteiro e positivo, calcule e mostre o valor de E, conforme a fórmula a seguir:
E = 1 + 1/1! + ½! + 1/3! + ... + 1/N! */
import java.util.Scanner;
class Main {
public static void main(String[] args) {
int numero;
double r = 0, fatorial;
Scanner scanner = new Scanner(System.in);
System.out.print("Digite um numero:");
numero = scanner.nextInt();
for(int i = 1; i <= numero; i++) {
fatorial = 1;
for(int j = 1; j <= i; j++) {
fatorial = fatorial * j;
}
r = r + 1 / fatorial;
}
System.out.print(r);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment