1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
#include <stdio.h>
int main()
{
double first ;
printf(" Enter a value for the first number:> ");
scanf( "%lf", &first );
double second ;
printf("Enter a value for the second number:> ");
scanf( "%lf", &second );
// assume that first and second are within [INT_MIN,INT_MAX]
{
const double x = first ;
const double y = second ;
if( y != 0 )
{
const double quotient = x / y;
printf("\nWhen x and y are both type double, x / y = %.2f / %.2f = %.2f\n", x, y, quotient);
}
}
{
const int x = first ;
const int y = second ;
if( y != 0 )
{
const double quotient = x / y;
printf("When x and y are both type int, x / y = %d / %d = %.2f\n", x, y, quotient);
}
}
{
const double x = first ;
const int y = second ;
if( y != 0 )
{
const double quotient = x / y;
printf("When x is of type double and y is of type int, x / y = %.2f / %d = %.2f\n", x, y, quotient);
}
}
{
const int x = first ;
const double y = second ;
if( y != 0 )
{
const double quotient = x / y;
printf("When x is of type int and y is of type double, x / y = %d / %.2f = %.2f\n", x, y, quotient);
}
}
}
|