C Greater-Than Or Equal-To Operator

In C, the Greater-Than Or Equal-To >= operator is a comparison operator used to check whether the left operand is greater than or equal to the right operand. If the condition is true, it returns 1 (true); otherwise, it returns 0 (false).

The Greater-Than Or Equal-To >= operator is commonly used in conditional statements and loops to control program flow.


Syntax of the Greater-Than Or Equal-To Operator

The syntax to use the Greater-Than Or Equal-To operator is:

</>
Copy
variable1 >= variable2

Explanation:

  1. variable1: The first operand to compare.
  2. >=: The greater-than or equal-to comparison operator.
  3. variable2: The second operand to compare with the first operand.

The result of the comparison is 1 (true) if variable1 is greater than or equal to variable2, otherwise 0 (false).


    Examples of the Greater-Than Or Equal-To Operator

    1. Comparing Two Integers

    In this example, we will compare two integer values using the Greater-Than Or Equal-To >= operator and print the result.

    main.c

    </>
    Copy
    #include <stdio.h>
    
    int main() {
        int a = 10, b = 5;
    
        if (a >= b) {
            printf("a is greater than or equal to b.\n");
        } else {
            printf("a is less than b.\n");
        }
    
        return 0;
    }

    Explanation:

    1. We declare two integer variables a and b, initialized to 10 and 5.
    2. The if condition checks if a >= b.
    3. Since 10 >= 5 is true, the message “a is greater than or equal to b.” is printed.

    Output:

    a is greater than or equal to b.

    2. Using Greater-Than Or Equal-To with User Input

    In this example, we will take two numbers as input from the user and compare them using the Greater-Than Or Equal-To >= operator.

    main.c

    </>
    Copy
    #include <stdio.h>
    
    int main() {
        int num1, num2;
    
        // Taking user input
        printf("Enter first number: ");
        scanf("%d", &num1);
        printf("Enter second number: ");
        scanf("%d", &num2);
    
        // Checking condition
        if (num1 >= num2) {
            printf("%d is greater than or equal to %d.\n", num1, num2);
        } else {
            printf("%d is less than %d.\n", num1, num2);
        }
    
        return 0;
    }

    Explanation:

    1. We declare two integer variables num1 and num2.
    2. The user inputs values for num1 and num2 using scanf().
    3. The if condition checks if num1 >= num2.
    4. If true, it prints “num1 is greater than or equal to num2“. Otherwise, it prints “num1 is less than num2“.

    Output (Example):

    Enter first number: 8
    Enter second number: 6
    8 is greater than or equal to 6.

    3. Using Greater-Than Or Equal-To in a Loop

    In this example, we will use the Greater-Than Or Equal-To >= operator to control the termination of a loop.

    main.c

    </>
    Copy
    #include <stdio.h>
    
    int main() {
        int i = 5;
    
        // Loop runs while i is greater than or equal to 1
        while (i >= 1) {
            printf("i = %d\n", i);
            i--;
        }
    
        return 0;
    }

    Explanation:

    1. We initialize an integer variable i to 5.
    2. The while loop runs as long as i >= 1.
    3. Inside the loop, i is printed and then decremented by 1.
    4. The loop stops when i becomes less than 1.

    Output:

    i = 5
    i = 4
    i = 3
    i = 2
    i = 1

    Conclusion

    The Greater-Than Or Equal-To >= operator in C:

    1. Checks if one value is greater than or equal to another.
    2. Returns 1 if true, otherwise returns 0.
    3. Used in conditions and loops to control program flow.