Advertisement
gonzalob

Untitled

Mar 28th, 2022
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6. int limite;
  7.  
  8. int nota;
  9.  
  10. int sumaNota = 0; //SI O SI en 0 porque sino viene basura
  11.  
  12. float promedio;
  13.  
  14. printf("ingrese la cantidad de veces\n");
  15. fflush(stdin);
  16. scanf("%d",&limite);
  17.  
  18.  
  19. /*
  20. //contador inicial ; condicion del ciclo ; incremento (paso)
  21. for (int indice = limite;indice>0;indice--)
  22. {
  23. printf("indice = %d\n",indice);
  24. }
  25. */
  26.  
  27.  
  28. for (int indice = 0;indice<limite;indice++)
  29. {
  30. //no afecta a la variable la suma en el print
  31. printf("ingrese nota # %d\n",(indice+1));
  32. fflush(stdin);
  33. scanf("%d",&nota);
  34. sumaNota = sumaNota + nota; //acumulador
  35. //sumaNota += nota;
  36.  
  37. }
  38.  
  39. printf("la suma de las notas es %d\n",sumaNota);
  40.  
  41. promedio = (float)(sumaNota/limite); //casteo o conversion on line
  42.  
  43. printf("el promedio es %f\n",promedio);
  44.  
  45.  
  46. return 0;
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement