Advertisement
Nasty

Progresión Aritmética

Apr 26th, 2015
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     cout << "Introduzca el primer termino: ";
  8.     float a; // primer termino
  9.     cin >> a;
  10.     cout << "Introduzca el segundo termino: ";
  11.     float b; // segundo termino
  12.     cin >> b;
  13.     float d = b - a; // diferencia
  14.     cout << "Diferencia: " << d << endl;
  15.     cout << "Terminos a mostrar: ";
  16.     int show; // numero de terminos a generar
  17.     cin >> show;
  18.     for(int x = 1; x <= show; x++)
  19.     {
  20.         cout << a + (d * (x - 1)) << endl;
  21.     }
  22.     float a_n = a + (d * (show - 1)); // el ultimo termino
  23.     float suma = (show * (a + a_n)) / 2; // suma de los terminos
  24.     cout << "Suma de todos los terminos: " << suma << endl;
  25.     return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement