Ejercico con vectores

#include <iostream> #include <stdlib.h> using namespace std; int main() { int ind[100], a = 1, b = 0, i = 1, cant = 0, temp; double pron, prom[100], sum; while (a == 1) { b++; sum = 0; for (int j = 1; j <= 5; j++) { cout << "Ingrese temperatura " << j << endl; cin >> temp; sum = sum + temp; cant++; } cout << "CANT: " << cant << endl; cout << "SUM: " << sum << endl; pron = sum / 5; if (i == 1) { prom[1] = pron; ind[1] = 0; } else { prom[i] = pron; if (prom[i] > prom[i-1]) ind[i] = 1; else { if (prom[i] < prom[i-1]) ind[i] = -1; else ind[i] = 0; } } i++; cout << "Agregar otros datos... (1 = si)" << endl; cin >> a; system("CLS"); } cout << "PROMEDIOS: [ "; for (int i = 1; i <= b; i++) cout << prom[i] << " "; cout << "]" << endl; cout << "INDICES: [ "; for (int i = 1; i <= b; i++) cout << ind[i] << " "; cout << "]" << " "; return 0; }
+ info: blogg-wilsontovar.rhcloud.com/ejercicios-resueltos-en-c-matrices-y-vectores/

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.