Program to Demonstrate Typecasting in C
Here is a program to demonstrate typecasting in C programming language.
#include#include void main(){ float result; int num1, num2; clrscr(); num1 = 10; num2 = 3; result = num1/num2; printf("\nBefore Typecasting: %f",result); /* As num1 and num2 are declared as int, it will return int value and it will get stored in the variable "result" as float i.e. 3.000000 To solve this problem we can use typecasting. */ result = (float)num1/num2; printf("\nAfter Typecasting: %f",result); getch(); }
Output:
Before Typecasting: 3.000000 After Typecasting: 3.333333
why getch(); is used?? as printf will deliver the output pls explain
getch() is used only so you can see the output on the screen after you run the file on your computer. it has no real use in this question.
in float after decimal point why there are 6 zeros