Program 3 - CSU1128 - CSE 2026 - Shoolini University

Program which demonstrates use of all operators of arithmatic, modulo, relational, logical bitwise, increment, decrement, assignment, and conditional operators.

Explanation

The following code is a C program that demonstrates the use of various operators in the C programming language. These operators include arithmetic, modulo, relational, logical, bitwise, increment, decrement, assignment, and conditional operators.

At the start of the program, the user is prompted to enter two integer values separated by a space, which are stored in the variables d and m. The program then uses these values to demonstrate the functionality of each type of operator.

Arithmetic operators include addition +, subtraction -, division /, and multiplication *. The result of each operation is printed to the console with a description of the operator used.

The modulo operator % returns the remainder of the division of two values. The program demonstrates its use by dividing d by m and printing the result.

Relational operators are used to compare two values. They include less than <, greater than >, less than or equal to <=, greater than or equal to >=, not equal to !=, and equal to ==. The program demonstrates the use of each of these operators by comparing d and m and printing the result.

Assignment operators allow values to be assigned to variables. The program demonstrates the use of the assignment operator = by assigning the value of m to d.

Logical operators are used to perform logical operations on values. The program demonstrates the use of the equal to == operator, the logical and && operator, and the logical or || operator.

Bitwise operators are used to perform bitwise operations on values. The program demonstrates the use of the logical not ! operator, the bitwise and & operator, the bitwise or | operator, and the bitwise exclusive or ^ operator.

Increment and decrement operators are used to increase and decrease the value of a variable. The program demonstrates the use of the post-increment ++ and post-decrement -- operators.

Conditional operators allow for the execution of certain statements based on a condition. The program demonstrates the use of the conditional operator if a>b by comparing d and m and printing the value of d if d is greater than m.

The program concludes by printing a summary of all the operations performed and the results.

Code

                    
/*
 * -----------------------------------------------------------
 * Logic Building with Computer Programming (CSU1128)
 * Instructor: Dr. Pankaj Vaidya | Author: Divya Mohan
 * 
 * This code is a part of the educational initiative by dmj.one
 * with aim of empowering and inspiring learners in the field of
 * Computer Science and Engineering through the respective courses.
 * 
 * (c) 2022, Divya Mohan for dmj.one. All rights reserved.
 * -----------------------------------------------------------
 */

#include <stdio.h>
int main()
{
    int d, m;
    printf("\n\n Program which demonstrates use of all operators of arithmatic, modulo, relational, logical bitwise, increment, decrement, assignment, and conditional operators. \n\n");
    printf("Enter 2 numbers with space and without decimal - (Example: 20 50) - and press enter: ");
    scanf("%d %d", &d, &m);

    /** Statement Generator - Instead of writing every sentence for printf - it can be done using a simple for loop.
        char arr[100][100] = {"+", "-", "/", "*", "%", "<", ">", "<=", ">=", "!=", "=", "==", "&&", "||", "!", "&", "|", "^", "a++", "a--", "if (a>b)", "if (b>a)", "\0"};
        for (int i = 0; i < 22; i++)
        {
            printf("printf(\"For the operator %s the value for aaaa and bbbb will be cccc \\n\", d, m, d %s m); \n", arr[i], arr[i]);
        }
    */
    // Program Start
    printf("\n\n Arithmatic Operators: \n");
    printf("\t For the operator + the value for %d and %d will be %d \n", d, m, d + m);
    printf("\t For the operator - the value for %d and %d will be %d \n", d, m, d - m);
    printf("\t For the operator / the value for %d and %d will be %d \n", d, m, d / m);
    printf("\t For the operator * the value for %d and %d will be %d \n", d, m, d * m);

    printf("\n\n Modulo Operator: \n");
    char mod[10][10] = {"%", "!"};
    printf("\t For the operator %s the value for %d and %d will be %d \n", mod[0], d, m, d % m);

    printf("\n\n Relational Operators: \n");
    printf("\t For the operator < the value for %d and %d will be %d \n", d, m, d < m);
    printf("\t For the operator > the value for %d and %d will be %d \n", d, m, d > m);
    printf("\t For the operator <= the value for %d and %d will be %d \n", d, m, d <= m);
    printf("\t For the operator >= the value for %d and %d will be %d \n", d, m, d >= m);
    printf("\t For the operator != the value for %d and %d will be %d \n", d, m, d != m);

    printf("\n\n Assignment Operators: \n");
    int e = d;
    d = m;
    printf("\t For the operator = the value for a (%d) will become the value of b (%d) \n", d, m);
    d = e;

    printf("\n\n Logical Operators: \n");
    printf("\t For the operator == the value for %d and %d will be %d \n", d, m, d == m);
    printf("\t For the operator && the value for %d and %d will be %d \n", d, m, d && m);
    printf("\t For the operator || the value for %d and %d will be %d \n", d, m, d || m);

    printf("\n\n Bitwise Operators: \n");

    printf("\t For the operator %s the value for %d and %d will be %d \n", mod[1], d, m, !m);
    printf("\t For the operator & the value for %d and %d will be %d \n", d, m, d & m);
    printf("\t For the operator | the value for %d and %d will be %d \n", d, m, d | m);
    printf("\t For the operator ^ the value for %d and %d will be %d \n", d, m, d ^ m);

    printf("\n\n Increment and Decrement Operators: \n");
    int o = d++;
    printf("\t For the operator a++ the value for %d and %d will be %d \n", d, m, o);
    int n = d--;
    printf("\t For the operator a-- the value for %d and %d will be %d \n", d, m, n);

    printf("\n\n Conditional Operators: \n");
    printf("\t For the operation - if (a>b) printf(a) - the value for %d and %d will be %d \n", d, m, d > m);
    printf("\t For the operation - if (b>a) printf(b) - the value for %d and %d will be %d \n", d, m, m > d);

    return 0;
}                    
                

Output

Program which demonstrates use of all operators of arithmatic, modulo, relational, logical bitwise, increment, decrement, assignment, and conditional operators.

Enter 2 numbers with space and without decimal - (Example: 20 50) - and press enter: 3 5

Arithmatic Operators:
 For the operator + the value for 3 and 5 will be 8
 For the operator - the value for 3 and 5 will be -2
 For the operator / the value for 3 and 5 will be 0
 For the operator * the value for 3 and 5 will be 15

Modulo Operator:
 For the operator % the value for 3 and 5 will be 3

Relational Operators:
 For the operator < the value for 3 and 5 will be 1
 For the operator> the value for 3 and 5 will be 0
 For the operator <= the value for 3 and 5 will be 1 For the operator>= the value for 3 and 5 will be 0
 For the operator != the value for 3 and 5 will be 1

Assignment Operators:
 For the operator = the value for a (5) will become the value of b (5)

Logical Operators:
 For the operator == the value for 3 and 5 will be 0
 For the operator && the value for 3 and 5 will be 1
 For the operator || the value for 3 and 5 will be 1

Bitwise Operators:
 For the operator ! the value for 3 and 5 will be 0
 For the operator & the value for 3 and 5 will be 1
 For the operator | the value for 3 and 5 will be 7
 For the operator ^ the value for 3 and 5 will be 6

Increment and Decrement Operators:
 For the operator a++ the value for 4 and 5 will be 3
 For the operator a-- the value for 3 and 5 will be 4

Conditional Operators:
 For the operation - if (a>b) printf(a) - the value for 3 and 5 will be 0
 For the operation - if (b>a) printf(b) - the value for 3 and 5 will be 1