Download as pdf or txt
Download as pdf or txt
You are on page 1of 61

Department of Electronics and Communication Engineering

National Institute of Technology, Calicut

ZZ1004D : Computer Programming


Lecture 6

Abdulkareem V
vabdulkareemv@gmail.com

August 21, 2018


Content
1

Example-if and nested if

Largest of 3 numbers

else-if construction

Bitwise Operators
Bitwise AND
Bitwise OR
Bitwise XOR

Abdulkareem V | C Programming - Lecture 6


Recall from last class
2

I Variable Declaration
I Constants in C
I Arithmetic Operators
I if-else statement
I Equality Operators
I Relational Operators
I Logical Operators

Abdulkareem V | C Programming - Lecture 6


Home Work
Nested if example
3

I Program to check whether a number is in between 10 & 100


#include < s t d i o . h>
void main ( )
{
int a ;
printf ( "Enter the number:" ) ;
scanf ( "%d" ,&a ) ;
if ( a>10 )
{ if ( a<100 )
printf ( "\n%d is in between 10 and 100\n" , a ) ;
else
printf ( "\n%d is not in between 10 and 100\n" , a ) ;
}
else
printf ( "\n%d is not in between 10 and 100\n" , a ) ;
}

Abdulkareem V | C Programming - Lecture 6


Home Work
Nested if example
4

I Program to check whether a number is in between 10 & 100


#include < s t d i o . h>
void main ( )
{
int a ;
printf ( "Enter the number:" ) ;
scanf ( "%d" ,&a ) ;
if ( a>10 )
if ( a<100 )
printf ( "\n%d is in between 10 and 100\n" , a ) ;
else
printf ( "\n%d is not in between 10 and 100\n" , a ) ;
else
printf ( "\n%d is not in between 10 and 100\n" , a ) ;
}

Abdulkareem V | C Programming - Lecture 6


Home Work
Nested if example
4

I Program to check whether a number is in between 10 & 100


#include < s t d i o . h>
void main ( )
{
int a ;
printf ( "Enter the number:" ) ;
scanf ( "%d" ,&a ) ;
if ( a>10 )
if ( a<100 )
printf ( "\n%d is in between 10 and 100\n" , a ) ;
else
printf ( "\n%d is not in between 10 and 100\n" , a ) ;
else
printf ( "\n%d is not in between 10 and 100\n" , a ) ;
}
I An expression followed by a semicolon is called a statement

Abdulkareem V | C Programming - Lecture 6


Home Work
Nested if example
4

I Program to check whether a number is in between 10 & 100


#include < s t d i o . h>
void main ( )
{
int a ;
printf ( "Enter the number:" ) ;
scanf ( "%d" ,&a ) ;
if ( a>10 )
if ( a<100 )
printf ( "\n%d is in between 10 and 100\n" , a ) ;
else
printf ( "\n%d is not in between 10 and 100\n" , a ) ;
else
printf ( "\n%d is not in between 10 and 100\n" , a ) ;
}
I An expression followed by a semicolon is called a statement
I Braces { & } are used to group declarations and statements
together to form a block, which is syntactically equivalent to a
single statement

Abdulkareem V | C Programming - Lecture 6


Home Work
Nested if example
4

I Program to check whether a number is in between 10 & 100


#include < s t d i o . h>
void main ( )
{
int a ;
printf ( "Enter the number:" ) ;
scanf ( "%d" ,&a ) ;
if ( a>10 )
if ( a<100 )
printf ( "\n%d is in between 10 and 100\n" , a ) ;
else
printf ( "\n%d is not in between 10 and 100\n" , a ) ;
else
printf ( "\n%d is not in between 10 and 100\n" , a ) ;
}
I An expression followed by a semicolon is called a statement
I Braces { & } are used to group declarations and statements
together to form a block, which is syntactically equivalent to a
single statement
I if-else block is considered as a single statement
Abdulkareem V | C Programming - Lecture 6
Nested if
5

I As in the above example nesting of ifs is allowed in C

Abdulkareem V | C Programming - Lecture 6


Nested if
5

I As in the above example nesting of ifs is allowed in C


I Since else part of an if-else is optional,there is an ambiguity
when an else if omitted from a nested if sequence.

Abdulkareem V | C Programming - Lecture 6


Nested if
5

I As in the above example nesting of ifs is allowed in C


I Since else part of an if-else is optional,there is an ambiguity
when an else if omitted from a nested if sequence.
I This is resolved by associating the else with the closest previous
else-less if.

Abdulkareem V | C Programming - Lecture 6


Nested if
5

I As in the above example nesting of ifs is allowed in C


I Since else part of an if-else is optional,there is an ambiguity
when an else if omitted from a nested if sequence.
I This is resolved by associating the else with the closest previous
else-less if.
Code 1 Code 2
if ( x>=0 ) if ( x>=0 )
if ( x>0 ) , { if ( x>0 )
printf ( "x is +ve" ) ; printf ( "x is +ve" ) ; }
else else
printf ( "x is -ve" ) ; printf ( "x is -ve" ) ;

Abdulkareem V | C Programming - Lecture 6


Nested if
5

I As in the above example nesting of ifs is allowed in C


I Since else part of an if-else is optional,there is an ambiguity
when an else if omitted from a nested if sequence.
I This is resolved by associating the else with the closest previous
else-less if.
Code 1 Code 2
if ( x>=0 ) if ( x>=0 )
if ( x>0 ) , { if ( x>0 )
printf ( "x is +ve" ) ; printf ( "x is +ve" ) ; }
else else
printf ( "x is -ve" ) ; printf ( "x is -ve" ) ;

I In code 1 the else part is associated with the inner if (if(x > 0))

Abdulkareem V | C Programming - Lecture 6


Nested if
5

I As in the above example nesting of ifs is allowed in C


I Since else part of an if-else is optional,there is an ambiguity
when an else if omitted from a nested if sequence.
I This is resolved by associating the else with the closest previous
else-less if.
Code 1 Code 2
if ( x>=0 ) if ( x>=0 )
if ( x>0 ) , { if ( x>0 )
printf ( "x is +ve" ) ; printf ( "x is +ve" ) ; }
else else
printf ( "x is -ve" ) ; printf ( "x is -ve" ) ;

I In code 1 the else part is associated with the inner if (if(x > 0))
I If that isn’t what you want, braces must be used to force the
proper association as in code 2

Abdulkareem V | C Programming - Lecture 6


Nested if
5

I As in the above example nesting of ifs is allowed in C


I Since else part of an if-else is optional,there is an ambiguity
when an else if omitted from a nested if sequence.
I This is resolved by associating the else with the closest previous
else-less if.
Code 1 Code 2
if ( x>=0 ) if ( x>=0 )
if ( x>0 ) , { if ( x>0 )
printf ( "x is +ve" ) ; printf ( "x is +ve" ) ; }
else else
printf ( "x is -ve" ) ; printf ( "x is -ve" ) ;

I In code 1 the else part is associated with the inner if (if(x > 0))
I If that isn’t what you want, braces must be used to force the
proper association as in code 2
I This kind of bug can be hard to find; it’s a good idea to use
braces when there are nested ifs.
Abdulkareem V | C Programming - Lecture 6
Home Work
6

I Program to check whether a number is in between 10 & 100


#include < s t d i o . h>
void main ( )
{
int a ;
printf ( "Enter the number:" ) ;
scanf ( "%d" ,&a ) ;
if ( 10<a<100 )
printf ( "\n%d is in between 10 and 100\n" , a ) ;
else
printf ( "\n%d is not in between 10 and 100\n" , a ) ;
}

Abdulkareem V | C Programming - Lecture 6


Home Work
6

I Program to check whether a number is in between 10 & 100


#include < s t d i o . h>
void main ( )
{
int a ;
printf ( "Enter the number:" ) ;
scanf ( "%d" ,&a ) ;
if ( 10<a<100 )
printf ( "\n%d is in between 10 and 100\n" , a ) ;
else
printf ( "\n%d is not in between 10 and 100\n" , a ) ;
}

I 10 < a < 100 means (10 < a) < 100

Abdulkareem V | C Programming - Lecture 6


Home Work
6

I Program to check whether a number is in between 10 & 100


#include < s t d i o . h>
void main ( )
{
int a ;
printf ( "Enter the number:" ) ;
scanf ( "%d" ,&a ) ;
if ( 10<a<100 )
printf ( "\n%d is in between 10 and 100\n" , a ) ;
else
printf ( "\n%d is not in between 10 and 100\n" , a ) ;
}

I 10 < a < 100 means (10 < a) < 100


I 10 < a is 0(false) or 1(true) , hence 10 < a < 100 is always 1
(true)

Abdulkareem V | C Programming - Lecture 6


Home Work
6

I Program to check whether a number is in between 10 & 100


#include < s t d i o . h>
void main ( )
{
int a ;
printf ( "Enter the number:" ) ;
scanf ( "%d" ,&a ) ;
if ( 10<a<100 )
printf ( "\n%d is in between 10 and 100\n" , a ) ;
else
printf ( "\n%d is not in between 10 and 100\n" , a ) ;
}

I 10 < a < 100 means (10 < a) < 100


I 10 < a is 0(false) or 1(true) , hence 10 < a < 100 is always 1
(true)
I Hence this program will always print a is in between 10 and 100

Abdulkareem V | C Programming - Lecture 6


Home Work
Logical operator example
7

I Program to check whether a number is in between 10 & 100


#include < s t d i o . h>
void main ( )
{
int a ;
printf ( "Enter the number:" ) ;
scanf ( "%d" ,&a ) ;
if ( a>10 && a<100 )
printf ( "\n%d is in between 10 and 100\n" , a ) ;
else
printf ( "\n%d is not in between 10 and 100\n" , a ) ;
}

Abdulkareem V | C Programming - Lecture 6


Home Work
8

I Write a program to find the largest of three numbers


#include < s t d i o . h>
int main ( )
{
int a , b , c ;
printf ( "Enter the numbers:" ) ;
scanf ( "%d %d %d" ,&a ,& b ,& c ) ;
if ( a>b )

return 0 ;
}

Abdulkareem V | C Programming - Lecture 6


Home Work
9

I Write a program to find the largest of three numbers


#include < s t d i o . h>
int main ( )
{
int a , b , c ;
printf ( "Enter the numbers:" ) ;
scanf ( "%d %d %d" ,&a ,& b ,& c ) ;
if ( a>b )
if ( a>c )

return 0 ;
}

Abdulkareem V | C Programming - Lecture 6


Home Work
10

I Write a program to find the largest of three numbers


#include < s t d i o . h>
int main ( )
{
int a , b , c ;
printf ( "Enter the numbers:" ) ;
scanf ( "%d %d %d" ,&a ,& b ,& c ) ;
if ( a>b )
if ( a>c )
printf ( "\n%d is largest \n" , a ) ;

return 0 ;
}

Abdulkareem V | C Programming - Lecture 6


Home Work
11

I Write a program to find the largest of three numbers


#include < s t d i o . h>
int main ( )
{
int a , b , c ;
printf ( "Enter the numbers:" ) ;
scanf ( "%d %d %d" ,&a ,& b ,& c ) ;
if ( a>b )
if ( a>c )
printf ( "\n%d is largest \n" , a ) ;
else
printf ( "\n%d is largest \n" , c ) ;

return 0 ;
}

Abdulkareem V | C Programming - Lecture 6


Home Work
12

I Write a program to find the largest of three numbers


#include < s t d i o . h>
int main ( )
{
int a , b , c ;
printf ( "Enter the numbers:" ) ;
scanf ( "%d %d %d" ,&a ,& b ,& c ) ;
if ( a>b )
if ( a>c )
printf ( "\n%d is largest \n" , a ) ;
else
printf ( "\n%d is largest \n" , c ) ;
else

return 0 ;
}

Abdulkareem V | C Programming - Lecture 6


Home Work
13

I Write a program to find the largest of three numbers


#include < s t d i o . h>
int main ( )
{
int a , b , c ;
printf ( "Enter the numbers:" ) ;
scanf ( "%d %d %d" ,&a ,& b ,& c ) ;
if ( a>b )
if ( a>c )
printf ( "\n%d is largest \n" , a ) ;
else
printf ( "\n%d is largest \n" , c ) ;
else
if ( b>c )
printf ( "\n%d is largest \n" , b ) ;

return 0 ;
}

Abdulkareem V | C Programming - Lecture 6


Home Work
14

I Write a program to find the largest of three numbers


#include < s t d i o . h>
int main ( )
{
int a , b , c ;
printf ( "Enter the numbers:" ) ;
scanf ( "%d %d %d" ,&a ,& b ,& c ) ;
if ( a>b )
if ( a>c )
printf ( "\n%d is largest \n" , a ) ;
else
printf ( "\n%d is largest \n" , c ) ;
else
if ( b>c )
printf ( "\n%d is largest \n" , b ) ;
else
printf ( "\n%d is largest \n" , c ) ;
return 0 ;
}

Abdulkareem V | C Programming - Lecture 6


Home Work
Relational operator
15

I Write a program to find the largest of three numbers


#include < s t d i o . h>
int main ( )
{
int a , b , c ;
printf ( "Enter the numbers:" ) ;
scanf ( "%d %d %d" ,&a ,& b ,& c ) ;
if ( a>b && a>c )
printf ( "\n%d is largest \n" , a ) ;
if ( b>a && b>c )
printf ( "\n%d is largest \n" , b ) ;
if ( c>a && c>b )
printf ( "\n%d is largest \n" , c ) ;
return 0 ;
}

Abdulkareem V | C Programming - Lecture 6


Home Work
Relational operator
15

I Write a program to find the largest of three numbers


#include < s t d i o . h>
int main ( )
{
int a , b , c ;
printf ( "Enter the numbers:" ) ;
scanf ( "%d %d %d" ,&a ,& b ,& c ) ;
if ( a>b && a>c )
printf ( "\n%d is largest \n" , a ) ;
if ( b>a && b>c )
printf ( "\n%d is largest \n" , b ) ;
if ( c>a && c>b )
printf ( "\n%d is largest \n" , c ) ;
return 0 ;
}

I Here it will always check all the three expressions

Abdulkareem V | C Programming - Lecture 6


Home Work
else-if 16

I Write a program to find the largest of three numbers


#include < s t d i o . h>
int main ( )
{
int a , b , c ;
printf ( "Enter the numbers:" ) ;
scanf ( "%d %d %d" ,&a ,& b ,& c ) ;
if ( a>b && a>c )
printf ( "\n%d is largest \n" , a ) ;

return 0 ;
}

Abdulkareem V | C Programming - Lecture 6


Home Work
else-if 17

I Write a program to find the largest of three numbers


#include < s t d i o . h>
int main ( )
{
int a , b , c ;
printf ( "Enter the numbers:" ) ;
scanf ( "%d %d %d" ,&a ,& b ,& c ) ;
if ( a>b && a>c )
printf ( "\n%d is largest \n" , a ) ;
else if ( b>c )
printf ( "\n%d is largest \n" , b ) ;

return 0 ;
}

Abdulkareem V | C Programming - Lecture 6


Home Work
else-if 18

I Write a program to find the largest of three numbers


#include < s t d i o . h>
int main ( )
{
int a , b , c ;
printf ( "Enter the numbers:" ) ;
scanf ( "%d %d %d" ,&a ,& b ,& c ) ;
if ( a>b && a>c )
printf ( "\n%d is largest \n" , a ) ;
else if ( b>c )
printf ( "\n%d is largest \n" , b ) ;
else
printf ( "\n%d is largest \n" , c ) ;
return 0 ;
}

Abdulkareem V | C Programming - Lecture 6


Home Work
else-if 18

I Write a program to find the largest of three numbers


#include < s t d i o . h>
int main ( )
{
int a , b , c ;
printf ( "Enter the numbers:" ) ;
scanf ( "%d %d %d" ,&a ,& b ,& c ) ;
if ( a>b && a>c )
printf ( "\n%d is largest \n" , a ) ;
else if ( b>c )
printf ( "\n%d is largest \n" , b ) ;
else
printf ( "\n%d is largest \n" , c ) ;
return 0 ;
}

I Here we used else-if construction for multi-way decision

Abdulkareem V | C Programming - Lecture 6


else-if construction
19

I The if-else statement is used to express decisions

Abdulkareem V | C Programming - Lecture 6


else-if construction
19

I The if-else statement is used to express decisions


I else-if construction is used to express multi-way decision

Abdulkareem V | C Programming - Lecture 6


else-if construction
19

I The if-else statement is used to express decisions


I else-if construction is used to express multi-way decision

Syntax
if(expression)
statement
else if(expression)
statement
else if(expression)
statement
...
else
statement;

Abdulkareem V | C Programming - Lecture 6


else-if construction
19

I The if-else statement is used to express decisions


I else-if construction is used to express multi-way decision

Syntax
if(expression)
statement
else if(expression)
statement
else if(expression)
statement
...
else
statement;
I The expressions are evaluated in order. If an expression is true,
the statement associated with it is executed, and this terminates
the whole chain.

Abdulkareem V | C Programming - Lecture 6


else-if construction
19

I The if-else statement is used to express decisions


I else-if construction is used to express multi-way decision

Syntax
if(expression)
statement
else if(expression)
statement
else if(expression)
statement
...
else
statement;
I The expressions are evaluated in order. If an expression is true,
the statement associated with it is executed, and this terminates
the whole chain.
I Each statement is either a single statement, or a block of them
Abdulkareem V | C Programming - Lecture 6
Bitwise Operators
20

I To perform bit-level operations in C programming, bitwise


operators are used.
Operator Meaning
& Bitwise AND
| Bitwise OR
∧ Bitwise Exclusive-OR
<< Left Shift
>> Right Shift
∼ one’s complement

Abdulkareem V | C Programming - Lecture 6


Bitwise Operators
20

I To perform bit-level operations in C programming, bitwise


operators are used.
Operator Meaning
& Bitwise AND
| Bitwise OR
∧ Bitwise Exclusive-OR
<< Left Shift
>> Right Shift
∼ one’s complement
I Bitwise operations can be performed on any type of integer value
in C but not on floating point values

Abdulkareem V | C Programming - Lecture 6


Bitwise AND Operator (&)
21

I When two values are bitwise ANDed in C, the binary


representations of the values are compared bit by bit

Abdulkareem V | C Programming - Lecture 6


Bitwise AND Operator (&)
21

I When two values are bitwise ANDed in C, the binary


representations of the values are compared bit by bit
I The truth table of bitwise AND is shown below
b1 b2 b1 & b2
0 0 0
0 1 0
1 0 0
1 1 1

Abdulkareem V | C Programming - Lecture 6


Bitwise AND Operator (&)
21

I When two values are bitwise ANDed in C, the binary


representations of the values are compared bit by bit
I The truth table of bitwise AND is shown below
b1 b2 b1 & b2
0 0 0
0 1 0
1 0 0
1 1 1
I The bitwise AND operator (&) is often used to mask off some set
of bits

Abdulkareem V | C Programming - Lecture 6


Bitwise AND Operator (&)
21

I When two values are bitwise ANDed in C, the binary


representations of the values are compared bit by bit
I The truth table of bitwise AND is shown below
b1 b2 b1 & b2
0 0 0
0 1 0
1 0 0
1 1 1
I The bitwise AND operator (&) is often used to mask off some set
of bits
I eg. n=n&3 will set all the bits of n to 0 except lower order 2 bits

Abdulkareem V | C Programming - Lecture 6


Bitwise AND Operator (&)
21

I When two values are bitwise ANDed in C, the binary


representations of the values are compared bit by bit
I The truth table of bitwise AND is shown below
b1 b2 b1 & b2
0 0 0
0 1 0
1 0 0
1 1 1
I The bitwise AND operator (&) is often used to mask off some set
of bits
I eg. n=n&3 will set all the bits of n to 0 except lower order 2 bits
I eg. 25 & 7 is 1

Abdulkareem V | C Programming - Lecture 6


Bitwise AND Operator (&)
21

I When two values are bitwise ANDed in C, the binary


representations of the values are compared bit by bit
I The truth table of bitwise AND is shown below
b1 b2 b1 & b2
0 0 0
0 1 0
1 0 0
1 1 1
I The bitwise AND operator (&) is often used to mask off some set
of bits
I eg. n=n&3 will set all the bits of n to 0 except lower order 2 bits
I eg. 25 & 7 is 1
I eg. What is 1 & 2 and 1 && 2 ?

Abdulkareem V | C Programming - Lecture 6


Bitwise AND Operator (&)
21

I When two values are bitwise ANDed in C, the binary


representations of the values are compared bit by bit
I The truth table of bitwise AND is shown below
b1 b2 b1 & b2
0 0 0
0 1 0
1 0 0
1 1 1
I The bitwise AND operator (&) is often used to mask off some set
of bits
I eg. n=n&3 will set all the bits of n to 0 except lower order 2 bits
I eg. 25 & 7 is 1
I eg. What is 1 & 2 and 1 && 2 ?
I 1 & 2 is 0 and 1 && 2 is 1

Abdulkareem V | C Programming - Lecture 6


Bitwise OR Operator (|)
22

I When two values are bitwise ORed in C, the binary


representations of the values are compared bit by bit

Abdulkareem V | C Programming - Lecture 6


Bitwise OR Operator (|)
22

I When two values are bitwise ORed in C, the binary


representations of the values are compared bit by bit
I The truth table of bitwise OR is shown below
b1 b2 b1 | b2
0 0 0
0 1 1
1 0 1
1 1 1

Abdulkareem V | C Programming - Lecture 6


Bitwise OR Operator (|)
22

I When two values are bitwise ORed in C, the binary


representations of the values are compared bit by bit
I The truth table of bitwise OR is shown below
b1 b2 b1 | b2
0 0 0
0 1 1
1 0 1
1 1 1
I The bitwise OR operator (|) is often used to set some bits to
ON(1)

Abdulkareem V | C Programming - Lecture 6


Bitwise OR Operator (|)
22

I When two values are bitwise ORed in C, the binary


representations of the values are compared bit by bit
I The truth table of bitwise OR is shown below
b1 b2 b1 | b2
0 0 0
0 1 1
1 0 1
1 1 1
I The bitwise OR operator (|) is often used to set some bits to
ON(1)
I eg. n=n|3 will set lower order 2 bits to 1

Abdulkareem V | C Programming - Lecture 6


Bitwise OR Operator (|)
22

I When two values are bitwise ORed in C, the binary


representations of the values are compared bit by bit
I The truth table of bitwise OR is shown below
b1 b2 b1 | b2
0 0 0
0 1 1
1 0 1
1 1 1
I The bitwise OR operator (|) is often used to set some bits to
ON(1)
I eg. n=n|3 will set lower order 2 bits to 1
I eg. 25|5 is

Abdulkareem V | C Programming - Lecture 6


Bitwise OR Operator (|)
22

I When two values are bitwise ORed in C, the binary


representations of the values are compared bit by bit
I The truth table of bitwise OR is shown below
b1 b2 b1 | b2
0 0 0
0 1 1
1 0 1
1 1 1
I The bitwise OR operator (|) is often used to set some bits to
ON(1)
I eg. n=n|3 will set lower order 2 bits to 1
I eg. 25|5 is 29

Abdulkareem V | C Programming - Lecture 6


Bitwise Exclusive-OR Operator (∧)
23

I Often called bitwise XOR operator

Abdulkareem V | C Programming - Lecture 6


Bitwise Exclusive-OR Operator (∧)
23

I Often called bitwise XOR operator


I The truth table of bitwise XOR is shown below
b1 b2 b1 ∧ b2
0 0 0
0 1 1
1 0 1
1 1 0

Abdulkareem V | C Programming - Lecture 6


Bitwise Exclusive-OR Operator (∧)
23

I Often called bitwise XOR operator


I The truth table of bitwise XOR is shown below
b1 b2 b1 ∧ b2
0 0 0
0 1 1
1 0 1
1 1 0
I Any value XORed with itself produces 0.

Abdulkareem V | C Programming - Lecture 6


Bitwise Exclusive-OR Operator (∧)
Example
24

#include < s t d i o . h>


int main ( )
{
int a=10 , b=20 ;
a=a ^ b ;
b=b ^ a ;
a=a ^ b ;
printf ( "a=%d \t b=%d \n" , a , b ) ;
return 0 ;
}

Abdulkareem V | C Programming - Lecture 6


Bitwise Exclusive-OR Operator (∧)
Example
24

#include < s t d i o . h>


int main ( )
{
int a=10 , b=20 ;
a=a ^ b ;
b=b ^ a ;
a=a ^ b ;
printf ( "a=%d \t b=%d \n" , a , b ) ;
return 0 ;
}

Output : a=20 b=10

Abdulkareem V | C Programming - Lecture 6


Bitwise Exclusive-OR Operator (∧)
Example
24

#include < s t d i o . h>


int main ( )
{
int a=10 , b=20 ;
a=a ^ b ;
b=b ^ a ;
a=a ^ b ;
printf ( "a=%d \t b=%d \n" , a , b ) ;
return 0 ;
}

Output : a=20 b=10

This program will swap the values in a and b.

Abdulkareem V | C Programming - Lecture 6


Home Work
25

I Write a program to check whether a number is even or odd using


bitwise operator
I Write a program to assign grade (S:90-100, A:80-89, B:70-79,
C:60-69, D:50-59, E:40-49, F:0-39) for a student in a subject
based on the mark obtained

Abdulkareem V | C Programming - Lecture 6


Thank you!

You might also like