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 :
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.
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework