How to make a vector? In what way do you do not go putting nota1;nota2;nota3;etc
? I made 2 codes, but they do not work for me. How to do with the theme of the average?
1) Enter the data of the students of an establishment consisting of NOMBRE
(string 30 characters), SEXO
(char), and NOTAS
of 10
coded materials of 0
a 9
(int). The income will end when you enter
the name FIN
.
2) Indicate the number of students in the establishment whose average is greater than or equal to 4
and less than 7
.
Transcript of the photocopy they asked to make:
Enter the data of the students of a consistent establishment in NAME (string of 30 characters), SEX (char) and NOTES of 10 coded materials from 0 to 9 (int). The income will end when it enter the name "END". It is known that the establishment has no more of 10,000 students. Print the list of the 10 best students. Indicate how many students are in the establishment whose average is greater than or equal to 4 and less than seven. Allow entry of a name and display all of its data, or, if it does not belong to the establishment.
Code 1:
#include stdio.h
#include stdlib.h
#include ncurses.h
#include string.h
struct promedio{
int nota1;
int nota2;
int nota3;
int nota4;
int nota5;
int nota6;
int nota7;
int nota8;
int nota9;
int nota10;
};
struct alumno{
char nombre[20];
char sexo[20];
int edad;
struct promedio prom;
}alumnos[100];
int main(){
int n,i,pmay;
int promedio[100], mayor = 0;
printf("Digite el total de alumnos: ");
scanf("%i",&n);
for(i=0;i<n;i++){
printf("%i. Digite su nombre: ",i+1);
scanf("%s",alumnos[i].nombre);
printf("%i. Digite su sexo: ",i+1);
scanf("%s",alumnos[i].sexo);
printf("%i. Digite sus notas: ",i+1);
scanf("%i %i %i %i %i %i %i %i %i %i",&alumnos[i].prom.nota1,
&alumnos[i].prom.nota2,&alumnos[i].prom.nota3,&alumnos[i].prom.nota4,
&alumnos[i].prom.nota5,&alumnos[i].prom.nota6,&alumnos[i].prom.nota7,&alumnos[i].prom.nota8,
&alumnos[i].prom.nota9,&alumnos[i].prom.nota10);
printf("\n");
promedio[i] = (alumnos[i].prom.nota1+alumnos[i].prom.nota2+alumnos[i].prom.nota3+alumnos[i].prom.nota4+alumnos[i].prom.nota5+
alumnos[i].prom.nota6+alumnos[i].prom.nota7+alumnos[i].prom.nota8+alumnos[i].prom.nota9+alumnos[i].prom.nota10)/3;
if(promedio[i] > mayor){
mayor = promedio[i];
pmay = i;
}
}
printf("\n- El Alumno con Mayor Promedio-\n");
printf("\nNombre: %s",alumnos[pmay].nombre);
printf("\nSexo: %s",alumnos[pmay].sexo);
printf("\nPromedio: %i\n",promedio[pmay]);
getch();
return 0;
}
Code 2:
#include <stdio.h>
#include <string.h>
#define MAX 100
struct {
char nombre[20];
char sexo;
int notas[10];
} alumno[MAX];
int main() {
int j,i=0,suma,a,b,c;
float promedio=0.0;
while (1) {
printf("Nombre del alumno (para terminar teclee FIN): ");
scanf("%s",alumno[i].nombre);
getchar();
if (strcmp(alumno[i].nombre,"FIN") == 0)
break;
else {
printf("Sexo: M o F: ");
scanf("%c",&alumno[i].sexo);
for (j=0; j<10; j++) {
printf("Ingrese nota # %d: ",j+1);
scanf("%d",&alumno[i].notas[j]);
}
}
printf("\n");
i += 1;
}
for (a=0; a<i; a++) {
suma = 0;
for (b=0; b<10; b++)
suma = suma+alumno[a].notas[b];
promedio = suma/3;
if (promedio >= 4 && promedio < 7)
c += 1;
}
printf("Total de alumnos con promedio >= 4 y promedio < 7 = ");
printf("%d",c);
return 0;
}