// 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 for another incorrect // version, and to division_correct.cpp // for the correct version. #include int main() { int a, b; printf("enter a and b\n"); scanf("%d %d", &a, &b); // This is an operation of ints, so it returns an int. // Although the result is stored in a double, the // fact that division was performed on ints means that // the result cannot have a decimal part. double c = a / b; // this prints out the incorrect result printf("c = %lf\n", c); }