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

  • برمجة سي شارب
  • برمجة

 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

الأجوبة

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();
        }
    }
}
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...