Created
August 12, 2011 00:17
-
-
Save carlossaraiva/1141151 to your computer and use it in GitHub Desktop.
Exercício 02 - Somatória 1/2 + 1/4 + 1/8 + ... + 1/2048
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @author Carlos Saraiva | |
import java.util.*; | |
public class Somatoria | |
{ | |
public static void main(String args[]) | |
{ | |
double n = 1; | |
double soma = 0; | |
System.out.println("Esse programa fará contém um algoritimo que faz a"); | |
System.out.println("somatória: 1/2 + 1/4...1/2048"); | |
while (n <= 2048) | |
{ | |
n = n * 2; | |
soma = soma + (1/n); | |
} | |
System.out.println("Somatória:" + soma); | |
System.out.println("Variável:" + n); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment