Advertisement
Guest User

Ejercicio 8 TP0

a guest
Aug 18th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.61 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Punto7 {  // basado en la formulas de sucesión aritmetica.
  3.     public static void main(String[] arg){
  4.         Scanner input = new Scanner(System.in);    
  5.                 System.out.println("ingrese cantidad de los primeros numeros impares que desee sumar");
  6.                 int pf =input.nextInt();        // Ingresa pf(posición final)
  7.                 int vf=(2*pf)-1;                // busca valor de pf()
  8.                 int sumatotal=((1+vf)/2)*pf;    // sumatoria de valor inicial (1) y final (vf),dividido por la distancia en común
  9.                 System.out.println(sumatotal);  // y finalmente multiplicado por la posicion final. Se muestra la suma total.
  10.     }
  11. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement