Professional Documents
Culture Documents
Mr. Subhas Chandra Nath Assistant Professor Department of Computer Application
Mr. Subhas Chandra Nath Assistant Professor Department of Computer Application
BCAC101
1 Lecture :: 5
Contents
Operators in C
Arithmetic Operator
Relational Operator
Logical Operator
Increment & Decrement Operator
Hands on Example
2
Operators in C
Example 1: Write a C program to reverse a 3 digit number using ‘/’ & ‘%’
operator.
#include<stdio.h>
#include<conio.h>
Output
void main() {
int n,a,b,c,rev;
clrscr();
printf("\nEnter the 3 digit number::");
scanf("%d",&n);
a=n/100; n=n%100; b=n/10; c=n%10;
rev=c*100+b*10+a;
printf("\nReverse Number=%d",rev);
5
getch(); }
Relational Operator
++a and a++ means the same thing when they form
statements independently & they behave differently
when they are used in expression or the R.H.S. of an
assignment statement.
Consider the following example
int x=10,y,z;
y=++x; // pre increment
printf (“X=%d Y=%d”, x,y); //X=11 & Y=11
z=x++; // post increment
9
printf (“X=%d Z=%d”, x,z); //X=12 & Z=11
Continue…
Similarly --a and a-- means the same thing when they
form statements independently & they behave
differently when they are used in expression or the
R.H.S. of an assignment statement.
Consider the following example
int p=50,q,r;
q=--p; // pre decrement
printf (“P=%d Q=%d”, p,q); //P=49 & Q=49
r=p--; // post decrement
10 printf (“P=%d R=%d”, p,r); //P=48 & R=49
Continue…
12
Thank You.
13