QP School
Arithmetic operations with short int in C - Printable Version

+- QP School (https://qomplainerzschool.lima-city.de)
+-- Forum: Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=3)
+--- Forum: C 18 Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=32)
+--- Thread: Arithmetic operations with short int in C (/showthread.php?tid=5147)



Arithmetic operations with short int in C - Qomplainerz - 07-26-2023

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.