Currently I am working on program where input is in the range 10^-6<=x<=10^6,and hence I want to use int64_t, but can't figure out how to take input using it.Please help!!
Asked
Active
Viewed 2,782 times
0
-
1From where? File, console? Network? – 0andriy Sep 01 '17 at 05:36
-
1`scanf` with the right specifier? – M.M Sep 01 '17 at 05:38
-
3There seems to be something missing from the question, since `10^-6` needs some sort of transformation before it can be represented as a `int` – user3386109 Sep 01 '17 at 06:06
-
1`10^-6` is `0.000001` and not an integer. Please explain coding goals. – chux - Reinstate Monica Sep 01 '17 at 19:24
2 Answers
7
The portable way is to use <inttypes.h>
and do
scanf("%" SCNd64, &your_variable)

One Guy Hacking
- 1,176
- 11
- 16
0
try this
int64_t x;
scanf("%lld", &x);
printf("ans is %lld", x);

roshan_nazareth
- 311
- 5
- 16
-
There is no guarantee that `int64_t` is the same as `long long`, and you get undefined behavior if that's not the case. Use the format in Jabberwock's answer instead. – cmaster - reinstate monica Aug 31 '20 at 13:23