Untitled
unknown
plain_text
4 years ago
1.8 kB
4
Indexable
//15. Un vector tiene la lista de Nro.de Registro y otro vector tiene las notas.Hacer un programa para obtener las tres mejores notas.Hay que tener cuidado cuando se intercambia los elementos del vector de Nro.de Registro también se debe intercambiar las notas. #include <iostream> #include <stdio.h> #include <stdlib.h> #include <time.h> using namespace std; void leerVector(float vec[], int n) { int i; for (i = 0; i < n; i++) { cout << "Vec[" << i << "] : "; cin >> vec[i]; } } void imprimaVector(float vec[], int n) { int i; cout << endl << "El vector es --->>" << endl; for (i = 0; i < n; i++) { cout << vec[i] << " "; } } void Notamayor3(float vec[], float vec2[], int n) { float aux, aux2; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (vec2[i] > vec2[j]) { aux = vec2[i]; vec2[i] = vec2[j]; vec2[j] = aux; aux = vec[i]; vec[i] = vec[j]; vec[j] = aux; } } } cout << endl << "La nota alta 1 es " << vec2[n - 1] << " pertenece al alumno: " << vec[n - 1]; cout << endl << "La nota alta 2 es " << vec2[n - 2] << " pertenece al alumno: " << vec[n - 2]; ; cout << endl << "La nota alta 3 es " << vec2[n - 3] << " pertenece al alumno: " << vec[n - 3]; ; } int main() { int n = 0; float resul, vec[100], vec2[100], ; cout << "\nNumeros de registro: "; cin >> n; leerVector(vec, n); imprimaVector(vec, n); cout << endl; leerVector(vec2, n); imprimaVector(vec2, n); Notamayor3(vec, vec2, n); return 0; }
Editor is loading...