Hello,
I'm having trouble trying to operate with long int and int variables. The long int variables are stored in an array, and when I print an operation like this:
Code:
#include <stdio.h>
int main(void) {
long int numbers[3] = {1, 2, 3};
printf("%ld\n", ((numbers[2] * numbers[2]) - (4 * numbers[1] * numbers[3])));
return 0;
}
I'm getting results like -6855564848099805175 or 5150792580894394377.
Type casting is not working either:
Code:
#include <stdio.h>
int main(void) {
long int numbers[3] = {1, 2, 3};
printf("%ld\n", (long int)((numbers[2] * numbers[2]) - (4 * numbers[1] * numbers[3])));
return 0;
}
Why is the operation not being done successfully?
I'm using GCC 7.3.0.
Thanks in advance.