Function for matching points

0

In an exercise, I need to create a function that returns TRUE if the points are identical. For the points, a structure was implemented as follows:

typedef struct //Estrutura definida para os pontos.
{
    double x; //Coordenadas X e Y.
    double y;
} Ponto;

The function I created was as follows:

int pontoCoincide(Ponto P, Ponto Q)
{
    int coincide = 0;
    if(P.x == Q.x && P.y == Q.y)
        coincide = 1;
    return coincide;
}

I wonder if what I've done is right and that's just it, or if there's something wrong. Remember that I need to create the function with exactly those parameters.

    
asked by anonymous 26.06.2017 / 19:22

1 answer

2

Your reasoning is correct and can be implemented in other ways:

Using ternary operators:

int pontoCoincide( Ponto P, Ponto Q )
{
    return (P.x == Q.x && P.y == Q.y) ? 1 : 0;
}

Or simply:

int pontoCoincide( Ponto P, Ponto Q )
{
    return (P.x == Q.x && P.y == Q.y);
}
    
26.06.2017 / 19:33