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

Phương thức MathF.Cos() trong C#

Phương thức MathF.Cos() trong C# trả về cosin của một giá trị float (tính bằng radian).

Cú pháp

public static float Cos (float val);

Tham số val là giá trị float (radian).

Ví dụ

using System; 
class Demo { 
    public static void Main(){ 
        float val1 = 70f; 
        float res = (val1 * (MathF.PI)) / 180; 
        Console.WriteLine(MathF.Cos(res)); 
    } 
}

Kết quả

0.34202

Ví dụ khác

using System; 
class Demo { 
    public static void Main(){ 
        float val1 = 90f; 
        float res = (val1 * (MathF.PI)) / 180; 
        Console.WriteLine(MathF.Cos(res)); 
    } 
}

Kết quả

-4.371139E-08