Answer to Question #298804 in C# for Zyke

Question #298804

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

1
Expert's answer
2022-02-17T02:16:12-0500
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();
        }
    }

   
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS