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

C Programming Language / Data Types in C Language

833

Program:

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

This Particular section is dedicated to Programs only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.