Home / Programs / Write a program to illustrate the results of type conversion between float to int data type.
Programming Example

Write a program to illustrate the results of type conversion between float to int data type.

👁 926 Views
💻 Practical Program
📘 Step by Step Learning
Write a program to illustrate the results of type conversion between float to int data type.

Program Code

/*
 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;

} 

Output

x = 1.400000e+003 i = 1400
x = 1.499900e+001 i = 14
x = 1.000000e+060 i = -2147483648
Press any key to continue . . .

Explanation

None

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.