C PROGRAMMING PROGRAM • OPERATORS & CONVERSIONS
Perform All Arithmetic Operations
Learn how to perform all arithmetic operations using a clear C program.
PROBLEM UNDERSTANDING
Input and expected output
Sample input
20 6
Sample output
Sum = 26 Difference = 14 Product = 120 Quotient = 3.33 Remainder = 2
COMPLETE C PROGRAM
Complete C implementation
#include <stdio.h>
int main(void)
{
int first, second;
printf("Enter two integers: ");
scanf("%d %d", &first, &second);
printf("Sum = %d\nDifference = %d\nProduct = %d\n", first + second, first - second, first * second);
if (second != 0) {
printf("Quotient = %.2f\nRemainder = %d\n", (double) first / second, first % second);
} else {
printf("Division and remainder are undefined for zero.\n");
}
return 0;
}CURRENT STEP
SELECTED LINE
EXPECTED OUTPUT FOR THE SAMPLE
Sum = 26 Difference = 14 Product = 120 Quotient = 3.33 Remainder = 2
Step 0 of 0
PROGRAM EXPLANATION
Algorithm and explanation
- Read the required input values.
- Apply each arithmetic operator and guard division against a zero divisor.
- Display the computed result.
Apply each arithmetic operator and guard division against a zero divisor.
EFFICIENCY
Time and space complexity
Time complexity
O(1)
Auxiliary space
O(1)
DEBUGGING CHECKLIST
Common mistakes
Check this
Use the correct format specifier for every variable.
Check this
Initialize variables before using their values.
Check this
Check braces, semicolons and input order carefully.
Try it yourself
Practice: Run the program with the sample input, predict its output, and then test one boundary case of your own.
