Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package baitap;
- import java.util.Scanner;
- public class baitap {
- public static int n;
- //---------ham tinh giai thua--------------
- public static double giaithua(int n){
- double tmp = 1;
- if (n>1) {
- for (int i = 2; i <= n; i++) {
- tmp *= i;
- }
- }
- return tmp;
- }
- /**
- * @param args the command line arguments
- * S = 1/1! + 1/2! + 1/3! + ... + 1/n!
- */
- public static void main(String[] args) {
- // TODO code application logic here
- float tong = 0.0f;
- Scanner reader = new Scanner(System.in);
- System.out.print("Nhap so tu nhien N = ");
- n = reader.nextInt();
- for (int i = 1; i <= n; i++) {
- tong += 1/giaithua(i);
- }
- System.out.println("tong day so la: " + tong);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment