- C program to test if a number is a power of 2
- C program to multiply two number without using multiplication(*) operator
- C program to display Fibonacci series
- C program to compare two numbers without using relational operators
- C program to convert roman number into decimal number
- C program to encrypt and decrypt the string
- C program to make calculator using switch case
- C program to convert temperature from degree celsius to fahrenheit
- Selection sort in C programming
- Binary search in C programming
- C program to sort array using bubble sort algorithm
- Linear Search in C Programming – Program and Explanation
- C program to swap two numbers
- C program to find LCM of two numbers
- C program to find GCD of two numbers
- C program to find LCM and GCD using recursion
- C program to display prime numbers between two numbers using function and without using function
- C program to check whether a string is palindrome or not
- C program to read a character from keyboard and print it in reverse case i.e if input is lower case output will be upper case and vice versa
- C program to check whether a number is prime or not
- C program to check whether a number is positive, negative or zero
- C program to check whether a number is palindrome or not
- C program to check leap year
- C program to check Armstrong number
- C program to calculate the area of square with and without using function
- C program to calculate mean using arrays
- C program to calculate area of circle

In this example, you will learn the simple logic behind **C program to compare two numbers without using relational operators** and its implementation in C program.

Don’t get amazed, there is a simple mathematical logic behind it which I will explain step by step.

- Add sum and difference of two numbers. This will cancel the effects of smallest number

(big + small) + (big - small)

By performing above calculation we will get a number that is twice the bigger one.

[adsense1]

- Now divide the number by 2 to get the original number.

Here is the implementation of above process in the program.

```
/*C program to find greater out of two
numbers without using comparison*/
#include<stdio.h>
#include<math.h>
int main()
{
int x, y;
printf("Enter two numbers:\n");
scanf("%d %d", &x, &y);
//finding largest number between two
printf("\nLargest number: %d\n", ((x + y) + abs(x - y)) / 2);
return 0;
}
```

**Output**

- Subtract the sum and difference of two numbers. This will cancel the effects of largest number

(big + small) - (big - small)

By performing above calculation we will get a number that is twice the smaller one.

- Now divide the number by 2 to get the original number.

Now let’s see how it is implemented in the program.

```
/*C program to find smaller out of two
numbers without using comparison*/
#include<stdio.h>
#include<math.h>
int main()
{
int x, y;
printf("Enter two numbers:\n");
scanf("%d %d", &x, &y);
//finding smaller number between two
printf("\nSmallest number: %d\n", ((x + y) - abs(x - y)) / 2);
return 0;
}
```

**Output**

**Explanation**

In both programs, we have used `math.h`

header file for using standard `abs( )`

math library function. This function is used for using absolute value i.e. positive values only.