C language handles typecasting implicitly. However, we can handle it explicitly in our programs too. Let's write a C program that performs basic arithmetic operations with typecasting.
Declare variables to store the results of the arithmetic operations as add
, subtract
, multiply
, divide
, and remainder
.
#include<stdio.h>
int main()
{
int a, b, add, subtract, multiply, remainder;
float divide;
printf("Enter two integers: ");
scanf("%d%d", &a, &b);
add = a + b;
subtract = a - b;
multiply = a * b;
divide = a / (float)b;
remainder = a % b;
printf("Addition of the numbers = %d\n", add);
printf("Subtraction of 2nd number from 1st = %d\n", subtract);
printf("Multiplication of the numbers = %d\n", multiply);
printf("Dividing 1st number from 2nd = %f\n", divide);
printf("Remainder on Dividing 1st number by 2nd is %d\n", remainder);
return 0;
}