C Program To Compare two variables

C Program to compare two variables

Hey Shouters !! Today we will understand C Program to Compare two variables. We can compare two variable to find some relation between them.

Some of the popular Relations are :

  1. To find the largest number
  2. To find the smallest number
  3. Check that the variables are equal or not.

1. C Program to find the largest number-

If you have two variables suppose a=10 and b =20. To find the largest number we have to compare the two variables using the relational operator greater than (>) to get the largest number.

2. C Program to find the smallest number-

If you have two variables suppose a=20 and b =30. To find the smallest number we have to compare the two variables using the relational operator lesser than (<) to get the smallest number.

3. C Program to check the variables are equal or not –

In this program, we will see how to check that the two variables are equal or not. We will use the relational operator double equals (==) to compare the variables.

Suppose a and b are two variables and a=25 and b =25. Then the if statement will work. and if a=25 and b =20 then else statement will be executed.

Now you can write a C Program to compare two variables to check other relations as well.

We daily add Multiple Choice Questions for placement preparation questions and technical interview preparation on the Instagram page. Check the Instagram account: Shout Coders

Frequently Asked Questions?

❓ Can we use Conditional operator in the above comparisons

Yes, Conditional operator (?:) is used to compare the two variables in any relation.

❓ Can we use functions for comparing the two variables

Yes, we can use functions to compare the two variables.

❓ Is this program important for placement intweviews

This program is just for basic understanding and you have to understand this for solving tougher problems.

Recommended Posts –

  1. Introduction to C language
  2. Structure of C program
  3. C Program to add two numbers
  4. C Program to reverse a number
  5. Difference between C and C ++.

1 thought on “C Program To Compare two variables

Leave a Reply

Your email address will not be published. Required fields are marked *

Close Bitnami banner
Bitnami