Q:

Write a C# Sharp program to find the maximum and minimum number from a given string of numbers separated by single space

0

 Write a C# Sharp program to find the maximum and minimum number from a given string of numbers separated by single space. 

Expected Output :

Original string of numbers: 3 4 8 9 0 2 1
Maximum and minimum number of the said string: 9, 0

Original string of numbers: -2 -1 0 4 10
Maximum and minimum number of the said string: 10, -2

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

using System;
using System.Linq;
namespace exercises
{
    class Program
    {
        static void Main(string[] args)
        {
            string str_num = "3 4 8 9 0 2 1";
            Console.WriteLine("Original string of numbers: "+str_num);
            Console.WriteLine("Maximum and minimum number of the said string: "+test(str_num));
            str_num = "-2 -1 0 4 10";
            Console.WriteLine("\nOriginal string of numbers: " + str_num);
            Console.WriteLine("Maximum and minimum number of the said string: " + test(str_num));
        }
        public static string test(string str_num)
        {
            var result = str_num.Split(' ').Select(int.Parse).ToArray();
            return result.Max() + ", " + result.Min();
        }
    }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now