Advertisement
Primitiv0

Grades

Sep 10th, 2019
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. float promedio(int valores[], int cantidad) {
  4.     int i;
  5.     float suma = 0.0;
  6.  
  7.     for (i = 0; i < cantidad; ++i)
  8.         suma += valores[i];
  9.  
  10.     return suma / (float) cantidad;
  11. }
  12.  
  13.  
  14. int main() {
  15.  
  16.     int notas[10];
  17.     char nombre[20];
  18.     char opcion[3];
  19.     int n, i;
  20.  
  21.     do {
  22.         printf("Ingrese nombre del alumno: ");
  23.         scanf("%s", nombre);
  24.  
  25.         printf("Cuantas notas tiene %s? ", nombre);
  26.         scanf("%d", &n);
  27.  
  28.         for (i = 0; i < n; ++i) {
  29.             printf("  Nota %d: ", i + 1);
  30.             scanf("%d", &notas[i]);
  31.         }
  32.  
  33.         printf("El promedio de %s es %.1f\n", nombre, promedio(notas, n));
  34.  
  35.         printf("Desea calcular mas promedios (si/no)? ");
  36.         scanf("%s", opcion);
  37.  
  38.     } while (opcion[0] == 's' || opcion[0] == 'S');
  39.  
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement