Arithmetic Operators in C

Programming in the C language often begins with mastering its fundamental building blocks, and arithmetic operators are among the most crucial. In this article, we’ll delve into the basics of C programming by exploring the commonly used arithmetic operators: addition (+), subtraction (-), multiplication (*), division (/), and modulus (%). Through real-world examples and detailed explanations, you’ll gain a solid understanding of how to use these operators effectively. Understanding the basics of C programming, such as arithmetic operators, is essential for any aspiring programmer. In this article, we’ve explored the fundamental arithmetic operators in C (+, -, *, /, and %) with real-world examples and their respective outputs. Armed with this knowledge, you’re ready to tackle more complex programming tasks and build powerful C applications. Practice and experimentation are the keys to becoming proficient in C programming, so don’t hesitate to explore further and refine your skills.

Addition (+)

The addition operator (+) is used to add two or more values together. Let’s look at a simple example:

#include <stdio.h>

int main() {
    int num1 = 10;
    int num2 = 5;
    int result = num1 + num2;

    printf("The sum of %d and %d is %d\n", num1, num2, result);
    return 0;
}

Output:

The sum of 10 and 5 is 15

Subtraction (-)

The subtraction operator (-) is used to subtract one value from another. Here’s an example:

#include <stdio.h>
int main() {
    int num1 = 15;
    int num2 = 7;
    int result = num1 - num2;
    printf("The difference between %d and %d is %d\n", num1, num2, result);
    return 0;
}

Output:

The difference between 15 and 7 is 8

Multiplication (*)

The multiplication operator (*) is used to multiply two or more values. Take a look at this example:

#include <stdio.h>
int main() {
    int num1 = 8;
    int num2 = 4;
    int result = num1 * num2;
    printf("The product of %d and %d is %d\n", num1, num2, result);
    return 0;
}

Output:

The product of 8 and 4 is 32

Division (/)

The division operator (/) is used to divide one value by another. Here’s an example:

#include <stdio.h>
int main() {
    int num1 = 20;
    int num2 = 5;
    float result = (float)num1 / num2;
    printf("The result of %d divided by %d is %.2f\n", num1, num2, result);
    return 0;
}

Output:

The result of 20 divided by 5 is 4.00

Modulus (%)

The modulus operator (%) is used to find the remainder when one value is divided by another. Let’s see it in action:

#include <stdio.h>
int main() {
    int num1 = 17;
    int num2 = 5;
    int result = num1 % num2;
    printf("The remainder of %d divided by %d is %d\n", num1, num2, result);
    return 0;
}

Output:

The remainder of 17 divided by 5 is 2
Author: user