Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

C# Sharp Exercises: Maximum and minimum number from a given string of numbers separated by single space

C# Sharp String: Exercise-50 with Solution

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

Sample string : "3 4 8 9 0 2 1"

Sample Solution:-

C# Sharp Code:

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();
        }
    }
}

Sample 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

Flowchart :

Flowchart: C# Sharp Exercises - Maximum and minimum number from a given string of numbers separated by single space.

C# Sharp Code Editor:

Improve this sample solution and post your code through Disqus

Previous: Write a C# Sharp program to find the middle character(s) of a given string. Return the middle character if the length of the string is odd and return two middle characters if the length of the string is even.
Next: Write a C# Sharp program to check whether a given string is an “isograms” or not. Return True or False.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.