Alright I took that test on C++, I did quite well expcept
WTF is 7/9*9 = 0 in C/C++
I compiled this:
Code:#include <iostream.h>
int main()
{
int a = 7/9*9;
cout<<a;
return 0;
}
Printable View
Alright I took that test on C++, I did quite well expcept
WTF is 7/9*9 = 0 in C/C++
I compiled this:
Code:#include <iostream.h>
int main()
{
int a = 7/9*9;
cout<<a;
return 0;
}
First, something is wrong when the signature is five times as long as the post...
You are doing integer math -- meaning all fractional parts are discarded.
So, do each operation one at a time.
7 / 9 = 0 (fraction is discarded for integer math)
0 * 9 = 0.
So 7/9*9 = 0.
exactly...
#include <iostream.h>
int main()
{
float a = 7/9*9;
cout<<a;
return 0;
}