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

} 
                        

🖥 Program 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
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

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.

🔥 Practice suggestion

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.