printf("%f\n",x);
x has the type long, but the %f converter expects a floating-point value (of type double). Normally, when you pass an integer to a function that expects a floating-point value, the value is silently converted. However, this only applies to functions with a fixed number of arguments and a prototype indicating what the type of each argument is. It does not apply to variadic functions such as printf, because the compiler doesn't have enough information to know what to convert the value to: the format string may only be analyzed at runtime.
The language specification leaves the behavior of this program undefined: it can do anything. What is probably happening in this case is that x is stored in some integer register, and f is stored in some floating-point register. Since the printf calls are looking for a floating-point value, the compiled code goes to look in the first floating-point register. If you had passed a floating-point value to printf, the argument would end up in that register. But you didn't, so the value in that register was the last value that was stored there: the value read by scanf.
A good compiler would warn you that you're doing something wrong. For example, here's what I get when I compile your code with gcc -O -Wall:
a.c:2: warning: return type of 'main' is not 'int'
a.c: In function 'main':
a.c:7: warning: format '%d' expects type 'int', but argument 2 has type 'double'
a.c:9: warning: format '%f' expects type 'double', but argument 2 has type 'long int'
a.c:12: warning: format '%f' expects type 'double', but argument 2 has type 'long int'
a.c:15: warning: format '%f' expects type 'double', but argument 2 has type 'long int'
a.c:18: warning: format '%f' expects type 'double', but argument 2 has type 'long int'
I recommend configuring your compiler to print such warnings and paying attention to them.
To make your program work, either pass a floating-point value where one is expected, or tell printf to expect an integer value. Either
printf("%f", (double)x);
or
printf("%ld", x);