繁体   English   中英

在C#中使用Math.Sqrt函数时出错

[英]Getting Error while using Math.Sqrt function in C#


在下面给出的程序中,Math.Sqrt函数引发了一个错误,即“表达式表示variable', where a应有方法组”。 这里似乎有什么问题?


using System;
class program{
    static void Main(){
        Console.WriteLine("Enter the sides(a,b,c) of a triangle  :");
        int a = Convert.ToInt16(Console.ReadLine());
        int b = Convert.ToInt16(Console.ReadLine());
        int c = Convert.ToInt16(Console.ReadLine());
        double s = (a+b+c)/2;     
        double area = Math.Sqrt(s(s-a)(s-b)(s-c));
        if (a==b&&b==c){
            Console.WriteLine("This is an Equilateral trangle");
        }
        else if(a==b&&b!=c||a!=b&&b==c){
            Console.WriteLine("This is an Isosceles trangle");
        }
        else{
            Console.WriteLine("This is an Scalene trangle");
        }
    }
}here

C#不会像写方程式那样假定乘法,而是将s(sa)视为一个名为s的函数,该函数采用sa的参数。 您需要明确声明乘法符号:

double area = Math.Sqrt(s*(s-a)*(s-b)*(s-c));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM