Hi, i'm trying to use a long long integer to store a number, but when i run the compiled code i get a negative number. any help?
Code:#include <stdio.h>
void main() {
long long num1;
num1=600851475143;
printf("\n%d\n", num1);
}
Printable View
Hi, i'm trying to use a long long integer to store a number, but when i run the compiled code i get a negative number. any help?
Code:#include <stdio.h>
void main() {
long long num1;
num1=600851475143;
printf("\n%d\n", num1);
}
Use unsigned long long. Also, use the correct format flag for printf.
can you give me a list of C format flags? i never learned them
In that case add the "ll" suffix to that number, as it tells the compiler to store it using 64 bits.
Code:num1=600851475143ll;
adding the "ll" still returns a minus. using an unsigned long long doesn't work either. Any code examples? Thanks
I'd be %llu, and using unsigned long long together.
Thank you, so I was just using the wrong format flag. I am also using a signed variable, thanks. Problem solved. Now to figure out this Euler problem...
Well that's easy... Click Here!