Using the array below, write a source-code that read, display in horizontal setup, sum up the element
value and display the highest value.
Hint: var[?] > highest then highest = var[?]
Array: 2, 4, 5, 7, 8, 10
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
int[] arr = new int[6] { 2, 4, 5, 7, 8, 10 };
int sum = 0;
int highest = 0;
for (int i = 0; i < arr.Length; i++)
{
Console.Write("{0} ", arr[i]);
sum += arr[i];
if (arr[i] > highest)
highest = arr[i];
}
Console.WriteLine();
Console.WriteLine("Sum = {0} ", sum);
Console.WriteLine("Highest value = {0} ", highest);
Console.ReadKey();
}
}
}
Comments
Leave a comment