Questions
Some calculations are giving me the wrong answers. Can someone tell me the proper way to carry out math operations? (as in what data types to use for the numbers and so on)
// setup code
#include <stdio.h>
int num1 = 24;
int num2 = 7;
float result;
// main code
int main() {
printf("this is x:%d\n", num1);
printf("this is y:%d\n", num2);
result = num1 / num2; // this outputs 0
printf("this is int of x/y: %d\n", result);
result = (float) num1 / num2; // this outputs -536870912
printf("this is float of x/y: %d", result);
return 0;
}
// end
the first output is 0. I thought it would be 3
the second output is -536870912. I thought it would be 3.42
I've tried using other datatypes and typecasting which worked but I can't remember what they were and this is the code that I would like to use anyways.