# Operators in C

Hellooo the beautiful people……how are you all??

Welcome back with our new article. Today we are going to see some basic and very important operators used in C language. Soo…lets start.. 🙂

A) Arithmetic Operators:-

1)+, -, *, / -> Basic Arithmetic Operators

2) % -> Mod Operator returns remainder.

3) ++ -> Increment operator increases the
integer value by one.

4) — -> Decrement operator decreases the
integer value by one.

B) Relational Operators:-

1) Equal to (==):- Checks if the values of two operands are equal or not. If yes, then the condition becomes true.
For example: (10 == 20) is not true.

2) Not equal to (! =) :- Checks if the values of two operands are equal or not. If the values are not equal, then the condition becomes true.
For example: (10 != 20) is true.

3) Greater than (>) :– Checks if the value of left operand is greater than the value of right operand. If yes, then the condition becomes true
For example: (10 >20) is not true.

4) Less than (<) :- Checks if the value of left operand is less than the value of right operand. If yes, then the condition becomes true.
For example: (10 < 20) is true.

5) Greater than equal to (>=) :- Checks if the value of left operand is greater than or equal to the value of right operand. If yes, then the condition becomes true.
For example: (10 >= 20) is not true.

6) Less than equal to (<=) :-
Checks if the value of left operand is less than or equal to the value of right operand. If yes, then the condition becomes true.
For example: (10 <= 20) is true.

C) Logical Operators:-

1) Logical AND (&&) :- Called Logical AND operator. If both the operands are non-zero, then the condition becomes true. For example: (10 && 20) is false

2) Logical OR (||):- Called Logical OR Operator. If any of the two operands is non-zero, then the condition becomes true. For example: (10|| 20) is true.

3) Logical NOT (!) :- Called Logical NOT Operator. It is used to reverse the logical state of its operand. If a condition is true, then Logical NOT operator will make it false. For example: !(10 && 20) is true.

Hope you all must have got an idea about different operators in C.

Let’s see some of the examples using these operators👇

Q1) A program to add two numbers.

``````#include<stdio.h>
main( )
{
int a,b,c;
printf(“enter 2 nos”);
scanf(“%d %d”,&a,&b);
c=a+b;
}``````

Q2) A program to display areas of circle by accepting value of radius from user.

``````#include<stdio.h>
main()
{
float area;
printf(“Area is %f”,area);
}   ``````

Q3) A program to accept two numbers from user and interchange them.

``````#include<stdio.h>
main()
{
int x,y,temp;
printf(“enter 2 nos”);
scanf(“%d %d”,&x,&y);
temp=x;
x=y;
y=temp;
printf(“Swapped value is %d %d”,x,y);
}``````

Q4) A program to accept a character and display previous and next character.

``````#include<stdio.h>
main()
{
char ch;
printf(“enter character”);
scanf(“%c”,&ch);
printf(“Previous char is %c”,ch-1);
printf(“Next char is %c”,ch+1);
}``````

Q5) A program to accept two numbers and calculate Arithmetic mean and Harmonic mean.

``````#include<stdio.h>
main()
{
int a,b;
float am,hm;
printf(“enter 2 nos”);
scanf(“%d %d”,&a,&b);
am= (a+b)/2;
hm=(a*b)/(a+b);
printf(“AM is %f”,am);
printf(“Hm is %f”,hm);
}``````

Thank you all for your patience…….. I hope you all will understand today’s topic… .

If you have any query, feel free to ask… .. I’ll try my best to resolve it.

Ok then will end here. Meet you all in next article till then good bye 🙂

#### You may also like...

This site uses Akismet to reduce spam. Learn how your comment data is processed.