How to multiply two integers represented as strings and return the result also as a string in C#

1 Answer

0 votes
using System;
using System.Numerics;

class Program
{
    static string MultiplyStrings(string num1, string num2) {
        // Convert strings to BigInteger for large number handling
        BigInteger n1 = BigInteger.Parse(num1);
        BigInteger n2 = BigInteger.Parse(num2);

        // Perform multiplication
        BigInteger result = n1 * n2;

        // Convert result back to string
        return result.ToString();
    }

    static void Main()
    {
        string num1 = "123";
        string num2 = "456";

        Console.WriteLine("Result: " + MultiplyStrings(num1, num2));
    }
}



/*
run:

Result: 56088

*/

 



answered Jun 5 by avibootz
...