promedio
Publicado por kelly (17 intervenciones) el 26/10/2022 05:03:53
Escriba un algoritmo que lea 142 números e informe la suma de todos y el
valor promedio.
valor promedio.
Valora esta pregunta
0
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
int n, suma = 0;
srand(time(NULL));
cout << endl << "Los numeros son: " << endl;
for (int i = 0; i < 142; i++)
{
n = rand() % 100 + 1;
suma += n;
cout << n << " ";
}
cout << endl << endl << "Suma: " << suma << ", Promedio: " << suma / 149.0f << endl;
return 0;
}