Contenido del Curso
Conceptos básicos de C#
Conceptos básicos de C#
Práctica de Indexación
Encuentra la media entre el elemento más grande y el más pequeño del array numbers
.
La media, también llamada promedio, representa el número central entre dos o más números. Por ejemplo, el valor medio entre 1
y 5
es 3
.
La fórmula para encontrar la media entre dos números es la suma de los dos números dividida por 2: (num1 + num2) / 2
Usa indexación para acceder a los elementos más pequeño y más grande del array.
Use indexing to access the smallest and the largest elements of the array.
main
using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { int[] numbers = { 5, 9, 27, 17, 19, 21, 0, -7, 10 }; int sum = ___; int mean = ___; Console.WriteLine(mean); } } }
The
sum
variable should contain the sum of the two values.Figure out the index of the smallest and the largest elements of the
numbers
array and access those elements via indexing (numbers[index]
), then store their sum in thesum
variable.The
mean
will be the sum divided by 2.
main
using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { int[] numbers = { 5, 9, 27, 17, 19, 21, 0, -7, 10 }; int sum = numbers[2] + numbers[7]; int mean = sum / 2; Console.WriteLine(mean); } } }
¡Gracias por tus comentarios!