Consider following program in C++:
#include <iostream>
int main()
{
float f = 9.9f, m = 3.3f;
float c = f % m;
std::cout << c;
return 0;
}
Shows an error: Illegal use of floating point
When I write same program in Java like:
class Test
{
public static void main(String args[])
{
float f = 9.9f, m = 3.3f;
float c = f % m;
System.out.println(c);
}
}
Gives me the output: 3.2999997
and also in C#:
using System;
class Test
{
public static void Main()
{
float f = 9.9f, m = 3.3f;
float c = f % m;
Console.WriteLine(c);
}
}
gives output: 3.3
Why the same programming logic gives three different outputs in different language? Why we can't use modulo %
with floating point numbers in C/C++ but can use in Java and C#?
Sorry if it is a fool question...I am a student...thanks.