Create a program that will use a function, that will perform and display the sum, difference, product, and quotient of 2 numbers.
#include <stdio.h>
void arithmetic(int a, int b) {
int sum, dif, prod;
double quot;
sum = a + b;
dif = a - b;
prod = a * b;
if (b != 0) {
quot = (double) a / b;
}
printf("The sum of %d and %d is %d\n", a, b, sum);
printf("The difference of %d and %d is %d\n", a, b, dif);
printf("The product of %d and %d is %d\n", a, b, prod);
if (b != 0) {
printf("The quotient of %d and %d is %f\n", a, b, quot);
}
else {
printf("Can\'t divide by 0\n");
}
}
int main() {
int a, b;
printf("Enter two integers: ");
scanf("%d %d", &a, &b);
arithmetic(a, b);
return 0;
}
Comments
Leave a comment