// A simple example of how problems can arise when // we perform operations such as division on integers, // and we want these operations to produce real numbers // as results. In C, operations on integers produce // integer results. // // refer to division_incorrect1.cpp and division_incorrect2.cpp // for incorrect versions. #include int main() { int a, b; printf("enter a and b\n"); scanf("%d %d", &a, &b); double a2 = (double) a; double b2 = (double) b; // This is an operation of doubles, and the result is stored // in a double. // Even if the division result is not an integer, // c will still hold the true division result. double c = a2 / b2; // this prints out the incorrect result printf("c = %lf\n", c); }