w3resource

C#: Find the minimum value from two given two numbers, represented as string

C# Sharp Basic: Exercise-66 with Solution

Min Value from Two String Numbers

Write a C# Sharp program to find the minimum value from two numbers given to you, represented as a string.

Sample Solution:

C# Sharp Code:

using System;

namespace exercises
{
    class Program
    {
        // Main method where the program execution begins
        static void Main(string[] args)
        {
            // Calls the test function with two string arguments and prints the result
            Console.WriteLine(test("12", "43"));
        }

        // Function to compare two string representations of numbers and return the smaller one
        public static string test(string strn1, string strn2)
        {
            // Parsing the string representations of numbers to integers using Int32.Parse
            // Comparing the parsed integers using a ternary operator and returning the smaller string
            return Int32.Parse(strn1) > Int32.Parse(strn2) ? strn2 : strn1;
        }
    }
}

Sample Output:

12

Flowchart:

Flowchart: C# Sharp Exercises - Find the minimum value from two given two numbers, represented as string.

C# Sharp Code Editor:

Previous: Write a C# Sharp program to multiply all of elements of a given array of numbers by the array length.
Next: Write a C# Sharp program to create a coded string from a given string, using specified formula.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/csharp-exercises/basic/csharp-basic-exercise-66.php