Realizar Operações Aritméticas Básicas com Conversão de Tipos
A linguagem C lida com typecasting implicitamente. No entanto, podemos lidar com isso explicitamente em nossos programas também. Vamos escrever um programa em C que realiza operações aritméticas básicas com typecasting.
Declare variáveis para armazenar os resultados das operações aritméticas como add, subtract, multiply, divide e 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;
}