The site says "ANSI C" which is a commonly used misnomer for the C89/C90 standard revision... It is the obsolete deprecated version that no one should use anywhere - it does not accept for example //
comment characters.
The thing is that the implicit return 0
was added in C99. In C89 if main
does not return a value, behaviour is undefined. It seems that the solution is not accepted if main
does not explicitly return 0
.
URI Online Judge uses GCC 4.8.5. GCC 4.8.5 defaults to gnu89 "dialect" and without explicit return from main
the exit code is completely random. On the other hand calling it Ansi C is not appropriate either as it still does support things like //
for comments.
Thus:
#include <stdio.h>
#include <math.h>
int main(int argc, char const *argv[])
{
double x1, y1, x2, y2, result;
scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
result = sqrt(pow(x2 - x1, 2) + pow(y2 - y1 , 2));
printf("%.4lf\n", result);
return 0;
}
works but
#include <stdio.h>
#include <math.h>
int main(int argc, char const *argv[])
{
double x1, y1, x2, y2, result;
scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
result = sqrt(pow(x2 - x1, 2) + pow(y2 - y1 , 2));
printf("%.4lf\n", result);
return 42;
}
gives "Runtime error".
Another thing C89 does not accept either is %lf
to signify a double for printf
- l
is valid for only d
, i
, o
, u
, x
, and X
conversion specifiers. Notably, f
, is not listed! However either one works in URI, because glibc has for long supported C99.