Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Math.h function problem in c in code :: blocks

I wrote this code in C and it shows me this error.
I don’t know what it is or how can I solve it.

#include <stdio.h>
#include <math.h>

int main()
{
    int z;
    scanf("%d", &z);
    double x1 , x2 , x3 , x4 , y1 , y2 , y3 , y4;
    for(int i = 0;i<=z;i++)
        {
    scanf("%lf %lf", &x1 , &y1);
    scanf("%lf %lf", &x2 , &y2);
    scanf("%lf %lf", &x3 , &y3);
    scanf("%lf %lf", &x4 , &y4);
    double tule_parekhat1 = sqrt(pow(y2-y1, 2) + (pow(x2-x1), 2));
    double tule_parekhat2 = sqrt(pow(y3-y2, 2) + (pow(x3-x2), 2));
    double tule_parekhat3 = sqrt(pow(y4-y1, 2) + (pow(x4-x1), 2));
    double tule_parekhat4 = sqrt(pow(y4-y3, 2) + (pow(x4-x3), 2));

    }

}

I get the error (line 15, error : too few arguments to function ‘pow’)

I don’t know what it is.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Your code contains:

double tule_parekhat1 = sqrt(pow(y2-y1, 2) + (pow(x2-x1), 2));

with 2 call of pow function. In first call you correctly write pow(y2-y1, 2), actually calling the function with 2 parameters. But in second one, you write:

(pow(x2-x1), 2)

Here you only call pow with the single x2-x1 parameter and then use the comma (,) operator to discard that value and only retain the second one. This is incorrect and the compiler correctly raises an error.

You should write pow(x2-x1, 2) as you did for first call.


BTW, and IMHO you are abusing the pow function here. It is intended to be used for complex operation where both the operands are floating point values. Here the idiomatic way would be:

double tule_parekhat1 = sqrt((y2 - y1) * (y2 - y1) + (x2 - x1) * (x2 - x1));
...

using only addition and product operators.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading