Promedio de alumnos en matriz
Hallar el promedio de alumnos, sus notas están dentro de una matriz
#include<iostream>
using namespace std;
int main(){
int m,n,suma=0;
float prom;
cout<<"Ingrese la cantidad de alumnos: ";
cin>>m;
cout<<"Ingrese la cantidad de notas: ";
cin>>n;
cout<<"***********"<<endl;
int notas[m][n], total[m][n+2];
cout<<"Llenado de matriz"<<endl;
for(int i=0;i<m;i++){
cout<<"- - - - - - - - - - - - - - - - - - "<<endl;
for(int j=0;j<n;j++){
cout<<"Ingrese nota del alumno: "<<i+1<<": ";
cin>>notas[i][j];
}
}
cout<<"\n";
cout<<" "<<endl;
for(int i=0;i<m;i++){
suma=0;
cout<<"Alumno "<<i+1<<": ";
for(int j=0;j<n;j++){
cout<<notas[i][j]<<" ";
suma=suma+notas[i][j];
}
prom=1.0*suma/n;
cout<<"---> Promedio: "<<prom<<endl;
}
return 0;
}
#include<iostream>
using namespace std;
int main(){
int m,n,suma=0;
float prom;
cout<<"Ingrese la cantidad de alumnos: ";
cin>>m;
cout<<"Ingrese la cantidad de notas: ";
cin>>n;
cout<<"***********"<<endl;
int notas[m][n], total[m][n+2];
cout<<"Llenado de matriz"<<endl;
for(int i=0;i<m;i++){
cout<<"- - - - - - - - - - - - - - - - - - "<<endl;
for(int j=0;j<n;j++){
cout<<"Ingrese nota del alumno: "<<i+1<<": ";
cin>>notas[i][j];
}
}
cout<<"\n";
cout<<" "<<endl;
for(int i=0;i<m;i++){
suma=0;
cout<<"Alumno "<<i+1<<": ";
for(int j=0;j<n;j++){
cout<<notas[i][j]<<" ";
suma=suma+notas[i][j];
}
prom=1.0*suma/n;
cout<<"---> Promedio: "<<prom<<endl;
}
return 0;
}
Excelente blog amigo, me ha servido de mucha ayuda, gracias en verdad
ResponderBorrar