QP School

Full Version: Arithmetic operations with short int in C
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Example:

#include <stdio.h>

int main() {
    short int a = 1000;
    short int b = 200;

    // Addition
    short int sum = a + b;
    printf("Sum: %d\n", sum);

    // Subtraction
    short int difference = a - b;
    printf("Difference: %d\n", difference);

    // Multiplication
    short int product = a * b;
    printf("Product: %d\n", product);

    // Division
    short int quotient = a / b;
    printf("Quotient: %d\n", quotient);

    return 0;
}

Explanation:

Explanation: In this example, we perform basic arithmetic operations (addition, subtraction, multiplication, and division) using short int variables. The result of each operation is stored in a short int variable and then printed using the %d format specifier in printf.