Friday, September 2, 2016

// // Leave a Comment

C Arithmetic Program - Sum, Product, Difference, Quotient, Remainder

Question: Write a program that asks the user to enter two numbers, obtains them from the user and prints their sum, product, difference, quotient and remainder.

/* 
 * Author: AGHATISE OSAZUWA
 * Website: www.cscprogrammingtutorials.com 
 *
 * Program to calculate the sum, product, difference, quotient and remainder
 * of two numbers entered by the user.
 */

#include <stdio.h>
int main (){
    int num1, num2, sum, prod, diff, rem;
    puts("Enter two numbers: ");
    scanf("%d%d", &num1, &num2);
    sum = num1 + num2;
    prod = num1 * num2;
    diff = num1 - num2;
    rem = num1%num2;
    printf("The sum of %d and %d is %d.\n", num1, num2, sum);
    printf("The product of %d and %d is %d.\n", num1, num2, prod);
    printf("The difference of %d and %d is %d.\n", num1, num2, diff);
    printf("The remainder of %d and %d is %d.\n", num1, num2, rem);
    return 0;
}

C Arithmetic Program output
Program output
Click here to see other solutions to Deitel C How To Program exercises.

0 comments:

Post a Comment


DISCLAIMER: Opinions expressed in comments are those of the comment writers alone and does not reflect or represent the views of the post author. We reserve the right to delete any post deemed inappropriate or offensive and/or spammy. Please do not use abusive words/hate speech.

I Appreciate your valuable Feedback. So, Please DO NOT SPAM - Spam comments will be deleted immediately.

Don't use brand name in name field and you're not allowed to use links in comments unless it's necessary. Such comments will be removed immediately.

Thanks.