Grade Average
Stores five grades in an array and finds the average and the highest.
- Level
- Beginner
- Topic:
- Arrays
- Concepts:
- Input & output
- Arrays
- Para
Run, change and debug this example in your browser.
What you'll learn
Dimension creates an array with 5 slots, and the Para loop fills it with Leer notas[i]. The same loop adds up the total and tracks the maximum with a Si.
Code
Proceso PromedioNotas Definir notas Como Real Dimension notas[5] Definir suma, promedio, maximo Como Real Definir i Como Entero suma <- 0.0 maximo <- 0.0 // Llenar el arreglo Para i <- 1 Hasta 5 Hacer Escribir "Ingrese nota ", i, ": " Leer notas[i] suma <- suma + notas[i] // Encontrar la nota máxima Si notas[i] > maximo Entonces maximo <- notas[i] FinSi FinPara promedio <- suma / 5 Escribir "Promedio: ", promedio Escribir "Nota más alta: ", maximoFinProcesoFlowchart
Each block in the flowchart matches one instruction in the code.
Sample run
This is what the program shows when it runs. The answers typed by the user are highlighted.
Ingrese nota 1: User answer: 8.5Ingrese nota 2: User answer: 9.0Ingrese nota 3: User answer: 7.5Ingrese nota 4: User answer: 8.0Ingrese nota 5: User answer: 9.5Promedio: 8.5Nota más alta: 9.5
Challenge
Also show the lowest grade.
Show hint
Create a minimo variable that starts high, for example 10, and compare it with every grade.
Related examples
Store Inventory
Records the stock of each product and flags what to restock.
IntermediateBubble Sort
Sorts random numbers by swapping neighbors, and stops as soon as they're in order.
IntermediateSelection Sort
Finds the smallest of the remaining numbers and puts it in its place.
Intermediate