elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Estamos en la red social de Mastodon


  Mostrar Mensajes
Páginas: [1]
1  Programación / Programación C/C++ / Re: TENGO VARIAS DUDAS CON MI CODIGO en: 2 Abril 2019, 20:16 pm
Hola,

Soy nuevo en esto de la programación, vi tu duda y me pareció un buen reto el  poder encontrar solución tanto al programa, como a tus dudas, espero haber ayudado.

Código:
#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
int arreglo[5], i, numero = 5, positivos = 0, negativos = 0,  mayor = 0, menor = 0, posicion = 0, posicion1 = 0,x;
int pos[5] = {}, neg[5] = {};//inicializamos todas las posiciones en 0, ya que por defecto el compilador inicializa los elementos que no tienen un valor específico.



for (i = 0; i < numero; i++)//Se llena el arreglo con los 10 elementos que le pones
{
printf("Introduzca numero: \n");
cin >>arreglo[i];

     //vamos guardando en nuestros array auxiliares los valor negativos y positivos
if (arreglo[i] > 0) {
pos[i] = arreglo[i];


}else {
neg[i] = arreglo[i];
}

}

for (i = 0; i < numero; i++) {

if (arreglo[i] > mayor) {
mayor = arreglo[i];
posicion = i;

}

if (arreglo[i] < menor) {
menor = arreglo[i];
posicion1 = i;

}
}

for (i = 0; i < numero; i++)
{
if (arreglo[i] > 0)
positivos += arreglo[i];

}


for (i = 0; i < numero; i++)
{
if (arreglo[i] < 0)
negativos += arreglo[i];

}


//Salidas por pantalla
cout << "Los numero positivos son: ";
for (i = 0; i < numero; i++) //bucle que nos permitira imprimir todos los numero positivos como negativos
{
if (pos[i] > 0)   
{
cout << (pos[i]) << "  ";
}
}
printf("\nSuma de numeros positivos: %d", positivos);
printf("\nEl numero mayor es: %d y se encuentra en la posicion: %d", mayor, posicion);

cout << "\nLos numero negativos son: ";
for (i = 0; i < numero; i++) //bucle que nos permitira imprimir todos los numero positivos como negativos
{
if (neg[i] < 0)
{
cout << (neg[i]) << "  ";
}

}
printf("\nSuma de numeros negativos: %d", negativos);
printf("\nEl numero menor es: %d y se encuentra en la posicion: %d", menor, posicion1);

return 0;
}

 

YreX-DwX gracias por tus opciones me guié por ellas.

Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines