#include<stdio.h>
#include<conio.h>
int main()
{
printf("\n Division operation result");
printf("\n Two integers (5 & 2) : %d",5/2);
printf("\n One int & one float (5.5 & 2) : %g",5.5/2);
printf("\n Two integers (5 & 2) : %g",(float)5/2);
return 0;
}
The above program demonstrates how to change the data type of results obtained by division operations. The program begins by including the necessary header files: stdio.h and conio.h. The main function is then defined, which contains the program’s execution.
The first line of the main function uses the printf() function to display a label for the division operation and its result. The next line uses the printf() function to display the result of the division operation between two integers, 5 and 2. The division operation returns 2, the quotient of the division and not 0.5.
The second line uses the printf() function to display the result of a division operation between one integer and one float, 5.5 and 2. The division operation returns 2.75 as the quotient.
The third line uses the printf() function to display the result of the division operation between two integers, 5 and 2, but this time the numerator is casted to float using (float) before the division. This operation returns 2.5 as the quotient.
The return 0 statement at the end of the main function indicates that the program has successfully completed execution.
Thanks