Blue sky wrote:
Hi ,I think the follow program is right in logical But why the
compiler output :"square:declar ed identifier"
If that is the correct text of the error message, then your compiler is
defective. If an identifier is declared, that's never a good reason, in
itself, for issuing a diagnostic message. More to the point, the message
is not only pointless, but also inaccurate. The identifier "square" is
not declared anywhere in your program.
It's more likely that the compiler said "undeclared identifier". That is
a perfectly accurate description of your program, and more to the point,
it's precisely the biggest problem with your program. What you need is
to provide a declaration for square(). A definition is also needed, but
the definition could be in a different module.
#include<stdio. h>
#include<math.h >
int main()
{
double x1;
double x2;
double y1;
double y2;
double x;
double y;
double distance;
printf("Enter the local of points: ");
scanf("%1f%1f%1 f%1f",&x1,&x2,& y1,&y2);
x=fabs(x1-x2);
y=fabs(y1-y2);
You don't provide any definition for square(), so I can't be certain,
but I assume that square(x) calculates and returns the square of x. That
being the case, why are you bothering with the fabs() calls? The square
of (x1-x2) is always the same as the square of fabs(x1-x2), all you're
doing is wasting a small amount of space in your program and wasting a
small amount of time when it executes. Most importantly, you're creating
the potential for confusion when the next person who reads this code has
to waste time thinking "Is there some obscure reason why it might make
sense to call fabs() here?"
distance=sqrt(s quare(x)+square (y));
printf("The distance is %f",distance) ;
return 0;
}