Conteúdo do Curso
Noções Básicas de C#
Noções Básicas de C#
Prática de Indexação
Encontre a média entre o maior e o menor elemento do array numbers
.
A média, também chamada de média aritmética, representa o número central entre dois ou mais números. Por exemplo, o valor médio entre 1
e 5
é 3
.
A fórmula para encontrar a média entre dois números é a soma dos dois números dividida por 2: (num1 + num2) / 2
Use indexação para acessar os menores e maiores elementos do 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); } } }
Obrigado pelo seu feedback!