Skip to content
ExamplesEspañolWorkspace →

Grade Average

Stores five grades in an array and finds the average and the highest.

Level
Beginner
Topic:
Arrays
Concepts:
Input & output
Arrays
Para
Open in Codoritmo

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

array-average.psc · 21 lines
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: ", maximoFinProceso

Flowchart

Each block in the flowchart matches one instruction in the code.

Proceso PromedioNotasSíNoProceso PromedioNotasProceso PromedioNotasDefinir notas Como RealDefinir notas Como RealDimension notas[5]Dimension notas[5]Definir suma, promedio, maximo Como RealDefinir suma, promedio, maximoComo RealDefinir i Como EnteroDefinir i Como Enterosuma <- 0suma <- 0maximo <- 0maximo <- 0Para i <- 1 Hasta 5 HacerPara i <- 1 Hasta 5Escribir "Ingrese nota ", i, ": "Escribir "Ingrese nota ", i,": "Leer notas[i]Leer notas[i]suma <- suma + notas[i]suma <- suma + notas[i]Si notas[i] > maximo Entoncesnotas[i] > maximomaximo <- notas[i]maximo <- notas[i]promedio <- suma / 5promedio <- suma / 5Escribir "Promedio: ", promedioEscribir "Promedio: ",promedioEscribir "Nota más alta: ", maximoEscribir "Nota más alta: ",maximoFinProcesoFinProceso

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.

Open in Codoritmo
  • Store Inventory

    Records the stock of each product and flags what to restock.

    Intermediate
  • Bubble Sort

    Sorts random numbers by swapping neighbors, and stops as soon as they're in order.

    Intermediate
  • Selection Sort

    Finds the smallest of the remaining numbers and puts it in its place.

    Intermediate