# Algorithm of ages of N students, obtain average and only show the student who is older than the average obtained

1

I just need to show the student's older age based on the average obtained

``````#include<stdio.h>
#include<iostream>
using namespace std;

int main()
{

cout<<"Ingresa la cantidad de alumnos:  ";
cin>>n;

for(int i = 1; i<=n; i++)
{
cout<<"Edad de alumno "<< i <<" :  ";
}

return 0;
}
``````

asked by Francisco Cardenas 25.06.2017 в 06:31
source

1

The problem is poorly formulated, or missing data: are we sure that, at the most, there will only be 1 a student above the average age?

To show all ages above average, we have no choice but to store them somewhere, and check them, a posteriori , one after the other. Otherwise, we can only know if a certain age is above to all those introduced so far . Which can rule out several ages that meet the condition of being above average .

``````#include <iostream>
using namespace std;

int main( ) {
int *lista;
int acu = 0, n, idx, edad;

cout << "Ingrese la cantidad de alumnos: ";
cin >> n;

lista = new int[n];

for( idx = 0; idx < n; ++idx ) {
cout << "Edad del alumno "<< idx + 1 <<": ";

}

acu /= n;

cout << "Edad promedio: " << acu << "\n";
cout << "Edades superiores al promedio:\n;

for( idx = 0; idx < n; ++idx )
if( lista[idx] > acu ) {
cout << "alumno " << idx + 1 << ", edad " << lista[idx] << "\n";

return 0;
}
``````

source
1

The code can be something like this:

``````#include<iostream>
using namespace std;

int main()
{
double promedio=0, mayor=0, nAlumno=0;

cout<<"Ingresa la cantidad de alumnos:  ";
cin>>n;

for(int i = 1; i<=n; i++)
{
cout<<"Edad de alumno "<< i <<" :  ";

nAlumno = i;
}