lvalue required as left operand of assignment

前端 未结 2 1250
难免孤独
难免孤独 2021-01-29 16:17

i am trying to make a program which calculates the geometrical average.But i get this error mesage: lvalue required as left operand of assignment


 #include         


        
相关标签:
2条回答
  • 2021-01-29 16:39

    It is rather a mathematical problem than a programming problem. If you know that

    average*average = number1*number1+number2*number2

    you must evaluate average first. Solution is

    average = sqrt(number1*number1+number2*number2)

    EDIT1: but geometric mean should be computed as

    average = sqrt(number1 * number2)

    according to http://en.wikipedia.org/wiki/Geometric_mean

    0 讨论(0)
  • 2021-01-29 16:49

    Use this formula to calculate Geometric average:

    Geometric average = square root of (number1 * number2)

    #include<stdio.h>
    #include<math.h>
    
    int main()
    {
    
        float number1,number2,average;
    
        printf("enter the numbers which you want to calculate geometrical average of them > ");
        scanf("%f %f",&number1,&number2);
    
        average=sqrt(number1*number2);
    
        printf("Geometrical average is:%f",average);
    
        return 0;
    }
    
    0 讨论(0)
提交回复
热议问题