/*
Program: Write a program to illustrate the results of type conversion
between float to int data type.
Author: www.atnyla.com
*/
#include "stdio.h"
int main()
{
double x;
int i;
i = 1400;
x = i; /* conversion from int to double */
printf("x = %10.6le i = %d\n",x,i);
x = 14.999;
i = x; /* conversion from double to int */
printf("x = %10.6le i = %d\n",x,i);
x = 1.0e+60; /* a LARGE number */
i = x; /* won't fit - what happens ?? */
printf("x = %10.6le i = %d\n",x,i);
return 0;
}
x = 1.400000e+003 i = 1400
x = 1.499900e+001 i = 14
x = 1.000000e+060 i = -2147483648
Press any key to continue . . .
First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.
Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.