Realiza operaciones aritméticas básicas con casteo de tipos
El lenguaje C maneja el casteo de tipos implícitamente. Sin embargo, también podemos manejarlo explícitamente en nuestros programas. Escribamos un programa en C que realice operaciones aritméticas básicas con casteo de tipos.
Declara variables para almacenar los resultados de las operaciones aritméticas como add
, subtract
, multiply
, divide
y 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;
}