Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C#

เมธอด Math.BigMul() ใน C#

เมธอด Math.BigMul() ใน C# ใช้คำนวณผลคูณเต็มของสองจำนวน 32 บิต เมธอดนี้คืนค่าจำนวนเต็ม Int64 ที่เป็นผลคูณของทั้งสองจำนวน

ไวยากรณ์

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

พารามิเตอร์ val1 คือตัวคูณตัวแรก ส่วน val2 คือตัวคูณตัวที่สอง

ตัวอย่าง

ตัวอย่างที่ 1: คูณ Int32.MaxValue กับตัวเอง

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

ผลลัพธ์

Product of two numbers = 4611686014132420609

ตัวอย่างเพิ่มเติม

ตัวอย่างที่ 2: คูณสองจำนวน Int32 เฉพาะเจาะจง

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

ผลลัพธ์

Product of two numbers = 30480758034737508