how to use unsigned long long in C? was my syntax error?
[c]
#include <stdio.h>
int main() {
unsigned long long a;
scanf ("%llu", &a);
printf ("%llu", a);
return 0;
}
[/c]
input :
1234567890
output :
2883627802384794322
how can this happened?
thanks before.
unsigned long long in C
Moderator: Board moderators
-
- Guru
- Posts: 834
- Joined: Wed May 29, 2002 4:11 pm
- Location: Wroclaw, Poland
- Contact:
Your usage is good. Strange, but I couldn't repeat this behaviour ....
Are you using Windows or Unix ?
Dominik
Are you using Windows or Unix ?
Dominik
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)
Born from ashes - restarting counter of problems (800+ solved problems)
-
- New poster
- Posts: 7
- Joined: Wed Mar 19, 2003 3:16 pm
-
- New poster
- Posts: 22
- Joined: Sun Oct 20, 2002 6:41 pm
- Location: Lithuania
- Contact:
long long is not ANSI C type first of all, however most compilers support it (though support to GNU libc was added quite recently). Your problem might be the ll flag. Quoting scanf man page:
Initializing to 0 is not the solution as 1234567890 is a 32bit number, if you try with larger ones, it should behave incorrectly (upper 32bits will not be set probably).
The simple and straightforward way I have avoided it was by using C++ streams for input/output (though long long is not ANSI C++ either).
The q flag is the BSD 4.4 notation for long long, while ll or the usage of L in integer conversions is the GNU notation.
Initializing to 0 is not the solution as 1234567890 is a 32bit number, if you try with larger ones, it should behave incorrectly (upper 32bits will not be set probably).
The simple and straightforward way I have avoided it was by using C++ streams for input/output (though long long is not ANSI C++ either).
-
- Learning poster
- Posts: 90
- Joined: Sat Feb 15, 2003 1:39 am
- Location: Paris, France
- Contact:
about (unsigned) long long
The online judge supports long long int. If your compiler doesn't you can write your code whit long int and test it with small number. Before send your code, you only need to put something like : [c]#define long long long int[/c]
and replace all your %ld or %lu by %lld or %llu
and replace all your %ld or %lu by %lld or %llu
Not AC yet
AC at last 

