Challenge: Indexing
Find the mean between the largest and the smallest element of the numbers
array.
Mean, also called average, represents the central number between two or more than two numbers. For example the mean value between 1
and 5
is 3
.
Use indexing to access the smallest and the largest elements of the array.
main.cs
1234567891011121314151617using 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.cs
1234567891011121314151617using 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); } } }
Tak for dine kommentarer!
Spørg AI
Spørg AI
Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat
Awesome!
Completion rate improved to 1.59
Challenge: Indexing
Stryg for at vise menuen
Find the mean between the largest and the smallest element of the numbers
array.
Mean, also called average, represents the central number between two or more than two numbers. For example the mean value between 1
and 5
is 3
.
Use indexing to access the smallest and the largest elements of the array.
main.cs
1234567891011121314151617using 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.cs
1234567891011121314151617using 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); } } }
Tak for dine kommentarer!