What is Operators in c language?
An operator is a symbol that operates on a value or a variable. In operator is simply a symbol that is used to perform operations. There can be many types of operations like arithmetic, logical, bitwise, etc.
There are following types of operators to perform different types of operations in C language.
Arithmetic Operators
1-Write a program of Arithmetic Operaters in C language.
#include <stdio.h>
#include<conio.h>
int main ()
{
int a = 9, b = 4, c;
c = a+b;
printf ("a+b = %d \n",c);
c = a-b;
printf ("a-b = %d \n",c);
c = a*b;
printf ("a*b = %d \n",c);
c = a/b;
printf ("a/b = %d \n",c);
c = a%b;
printf ("Remainder when a divided by b = %d \n",c);
return 0;
}
Output:-
a+b = 13
a-b = 5
a*b = 36
a/b = 2
Remainder when a divided by b=1
#include <stdio.h>
#include<conio.h>
int main ()
{
int a = 10, b = 100;
float c = 10.5, d = 100.5;
printf ("++a = %d \n", ++a);
printf ("--b = %d \n", --b);
printf ("++c = %f \n", ++c);
printf ("--d = %f \n", --d);
return 0;
}
Output:-
++a = 11
--b = 99
++c = 11.500000
++d = 99.500000
Some basic C language program using while loop ,study easy
#include <stdio.h>
#include<conio.h>
int main ()
{
int a = 5, c;
c = a;
printf ("c = %d\n", c);
c += a;
printf ("c = %d\n", c);
c -= a;
printf ("c = %d\n", c);
c *= a;
printf ("c = %d\n", c);
c /= a;
printf ("c = %d\n", c);
c %= a;
printf ("c = %d\n", c);
return 0;
}
Output:-
c = 5
c = 10
c = 5
c = 25
c = 5
c = 0
#include <stdio.h>
#include<conio.h>
int main ()
{
int a = 5, b = 5, c = 10;
printf ("%d == %d is %d \n", a, b, a == b);
printf ("%d == %d is %d \n", a, c, a == c);
printf ("%d > %d is %d \n", a, b, a > b);
printf ("%d > %d is %d \n", a, c, a > c);
printf ("%d < %d is %d \n", a, b, a < b);
printf ("%d < %d is %d \n", a, c, a < c);
printf ("%d != %d is %d \n", a, b, a != b);
printf ("%d != %d is %d \n", a, c, a != c);
printf ("%d >= %d is %d \n", a, b, a >= b);
printf ("%d >= %d is %d \n", a, c, a >= c);
printf ("%d <= %d is %d \n", a, b, a <= b);
printf ("%d <= %d is %d \n", a, c, a <= c);
getch();
}
Output:-
5 == 5 is 1
5 == 10 is 0
5 > 5 is 0
5 > 10 is 0
5 < 5 is 0
5 < 10 is 1
5 != 5 is 0
5 != 10 is 1
5 >= 5 is 1
5 >= 10 is 0
5 <= 5 is 1
5 <= 10 is 1
Some basic C language program using do while loop concept in C , C++ and java
An operator is a symbol that operates on a value or a variable. In operator is simply a symbol that is used to perform operations. There can be many types of operations like arithmetic, logical, bitwise, etc.
There are following types of operators to perform different types of operations in C language.
- Arithmetic Operators
- Relational Operators
- Shift Operators
- Logical Operators
- Bitwise Operators
- Ternary or Conditional Operators
- Assignment Operator
Arithmetic Operators
1-Write a program of Arithmetic Operaters in C language.
#include <stdio.h>
#include<conio.h>
int main ()
{
int a = 9, b = 4, c;
c = a+b;
printf ("a+b = %d \n",c);
c = a-b;
printf ("a-b = %d \n",c);
c = a*b;
printf ("a*b = %d \n",c);
c = a/b;
printf ("a/b = %d \n",c);
c = a%b;
printf ("Remainder when a divided by b = %d \n",c);
return 0;
}
Operaters in c language |
Output:-
a+b = 13
a-b = 5
a*b = 36
a/b = 2
Remainder when a divided by b=1
2- Write a program of increment and decrement operators in C language.
#include <stdio.h>
#include<conio.h>
int main ()
{
int a = 10, b = 100;
float c = 10.5, d = 100.5;
printf ("++a = %d \n", ++a);
printf ("--b = %d \n", --b);
printf ("++c = %f \n", ++c);
printf ("--d = %f \n", --d);
return 0;
}
Output:-
++a = 11
--b = 99
++c = 11.500000
++d = 99.500000
Some basic C language program using while loop ,study easy
3- Write a program of assignment operators in C language.
#include <stdio.h>
#include<conio.h>
int main ()
{
int a = 5, c;
c = a;
printf ("c = %d\n", c);
c += a;
printf ("c = %d\n", c);
c -= a;
printf ("c = %d\n", c);
c *= a;
printf ("c = %d\n", c);
c /= a;
printf ("c = %d\n", c);
c %= a;
printf ("c = %d\n", c);
return 0;
}
Output:-
c = 5
c = 10
c = 5
c = 25
c = 5
c = 0
4- Write a program of relational operators in C language.
#include<conio.h>
int main ()
{
int a = 5, b = 5, c = 10;
printf ("%d == %d is %d \n", a, b, a == b);
printf ("%d == %d is %d \n", a, c, a == c);
printf ("%d > %d is %d \n", a, b, a > b);
printf ("%d > %d is %d \n", a, c, a > c);
printf ("%d < %d is %d \n", a, b, a < b);
printf ("%d < %d is %d \n", a, c, a < c);
printf ("%d != %d is %d \n", a, b, a != b);
printf ("%d != %d is %d \n", a, c, a != c);
printf ("%d >= %d is %d \n", a, b, a >= b);
printf ("%d >= %d is %d \n", a, c, a >= c);
printf ("%d <= %d is %d \n", a, b, a <= b);
printf ("%d <= %d is %d \n", a, c, a <= c);
getch();
}
Output:-
5 == 5 is 1
5 == 10 is 0
5 > 5 is 0
5 > 10 is 0
5 < 5 is 0
5 < 10 is 1
5 != 5 is 0
5 != 10 is 1
5 >= 5 is 1
5 >= 10 is 0
5 <= 5 is 1
5 <= 10 is 1
Some basic C language program using do while loop concept in C , C++ and java
0 Comments