Answer to Question #305288 in C for Thank you!

Question #305288

Create a program that will use a function, that will perform and display the sum, difference, product, and quotient of 2 numbers. 


1
Expert's answer
2022-03-03T09:59:05-0500
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS