Home

A program to explain type casting

C Programming Language 006

The following code shows how to write a program to explain type casting

Program

#include <stdio.h>

void main()
{
    int dividend, divisor;
    float f;
    printf("Enter dividend, divisor values: ");
    scanf("%d %d", &dividend, &divisor);
    f = dividend / divisor;
    printf("%f\n", f);
    f = (float)dividend / divisor;
    printf("%f", f);

    printf("\n");
}

Result

Enter dividend, divisor values: 2 5
0.000000
0.400000


Last Updated on

Next Post: Rules vs Guidelines →

Comments