favor
Publicado por Arman Garcia (2 intervenciones) el 14/06/2008 01:53:26
Alguien que me pueda ayudar, para realizar un algoritmo donde ingrese 100 numeros y determinar cuantos son positivos, negativos y ceros
Valora esta pregunta
0
#include <iostream>
using namespace std;
int main() {
const int totalNumeros = 100; // Número total de números a ingresar
int positivos = 0, negativos = 0, ceros = 0; // Contadores para positivos, negativos y ceros
int numero;
cout << "Ingresa " << totalNumeros << " números:" << endl;
for (int i = 0; i < totalNumeros; ++i) {
cout << "Número " << i + 1 << ": ";
cin >> numero;
// Determinar si el número es positivo, negativo o cero
if (numero > 0) {
positivos++;
} else if (numero < 0) {
negativos++;
} else {
ceros++;
}
}
// Mostrar resultados
cout << "\nResultados:" << endl;
cout << "Cantidad de números positivos: " << positivos << endl;
cout << "Cantidad de números negativos: " << negativos << endl;
cout << "Cantidad de ceros: " << ceros << endl;
return 0;
}