Created
May 15, 2013 14:47
-
-
Save gmfc/5584535 to your computer and use it in GitHub Desktop.
Seno
This file contains hidden or 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
| import javax.swing.*; | |
| import java.lang.*; | |
| class seno{ | |
| public static void main(String args[]){ | |
| double x, soma=0,fat,xgraus; | |
| int n; | |
| x = Double.parseDouble(JOptionPane.showInputDialog("Insira o angulo (em graus)")); | |
| do{n = Integer.parseInt(JOptionPane.showInputDialog("Entre com o numero de termos")); | |
| }while(n<=0); | |
| xgraus = x; | |
| x = rad(x); | |
| for (int i =0; i<=n; i++) | |
| soma += Math.pow(-1,i)*(Math.pow(x,2*i+1))/fatorial(2*i+1); | |
| JOptionPane.showMessageDialog(null,"Seno de "+xgraus+" é, aproximadamente, " + soma); | |
| } | |
| public static int fatorial(int fatin) {//calcula fatorial | |
| int fatout = 1; | |
| for (int i = 1; i <= fatin; i++) { | |
| fatout *= i; | |
| } | |
| return fatout; | |
| } | |
| public static double rad(double graus) {//CONVERSOR!! | |
| double radout = (graus * 3.14)/180; | |
| return radout; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment