Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> C#

Phương thức Math.BigMul() trong C#

Phương thức Math.BigMul() trong C# tính tích đầy đủ của hai số 32-bit. Phương thức trả về số nguyên Int64 là tích của hai số.

Cú pháp

public static long BigMul(int val1, int val2);

Tham số val1 là số thứ nhất, val2 là số thứ hai.

Ví dụ 1

using System;
public class Demo
{
    public static void Main()
    {
        int val1 = Int32.MaxValue;
        int val2 = Int32.MaxValue;
        Console.WriteLine("Product of two numbers = " + Math.BigMul(val1, val2));
    }
}

Đầu ra

Product of two numbers = 4611686014132420609

Ví dụ 2

using System;
public class Demo
{
    public static void Main()
    {
        Int32 val1 = 139897778;
        Int32 val2 = 217878786;
        Console.WriteLine("Product of two numbers = " + Math.BigMul(val1, val2));
    }
}

Đầu ra

Product of two numbers = 30480758034737508