60 Programming and Data Structures
00 00 00 00 00000010
15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 0
After execution
c«10
0000000 0 0 0 0 0 1 0 1 0
15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 0
Table of Inverter
Table 3.8 Table of Inverter logic
£NPurr(x)
OUTPUT (X)
0
1
i 0
SU M M ARY
You have now studied the various operators such as arithmetic, logical and relational which are
essential to write and execute programs. The precedence of the operators in the arithmetic operations
is also furnished in the form of a table. The conditional & comma operators and programs on them
are also described in this chapter. You are made aware of the logical operators OR, AND and NOT.
Full descriptions on bit wise operators have been illustrated. Numerous Simple examples have been
provided to the users to understand the various operators. The reader is expected to write more
programs on this chapter.
EXERC ISES
A) A nsw er the following questions.
1) Explain different types of operators available in C?
2) What are the uses of comma ( ,) and conditional (?) operators?
3) What are Unary operators and their uses?
4) Describe logical operators with their return values?
5) Distinguish between logical and bitwise operators.
6) What are the relational operators?
7) What is the difference between ' =' and '= ='?
8) What are the symbols used for a) OR b) AND c) XOR d) NOT operations?
9) Explain the precedence of operators in arithmetic operations?
10) List the operators from higher priority to least priority?
11) What is the difference between %f and %g?
12) What is the difference between division and modular division operations?
13) What are the ASCII codes? List the codes for digits 1 to 9, A to Z and a to z.
Operators and Expressions 61
B) A nsw er the follow ing by selecting the appropriate option.
1) What will be the output of the following program?
# include <stdio.h>
# include <conio.h>
void main()
{
in t ans=2;
in t m=10;
in t k;
k=!((ans<2) && (m>2) ) ;
p rin tf (" %d",k);
}
a) 1 b) 0 c) -1 d) 2
2) What will be the output of the following program?
# include <stdio.h>
# include <canio.h>
void main ()
{
in tm ,j= 3,k ;
m=2* j /2;
k=2* (j / 2) ;
c lr s c r ( ) j
printf ("tt m=%d k=%A,m,k);
}
a) m=3 k=2 b) m=3 k=3 c) m=2 k=3 d) m=2 k=2
3) What will be the value of x,y and z after execution of the following program?
# include <stdio.h>
# include <conio.h>
void main ()
{
int x,y,z;
y=2;
x=2;
x=2*(y++);
z=2*(++y);
printf (“n x=%d y=%d z=%d",x,y,z);
}
a) x=4 y=4 z=8 b) x=6 y=4 z=8 c) x=2 y=4 z=8 d) x=4 y=4 z=4
4) What will be the value of V after execution of the following program?
# include <stdio.h>
# include <canio.h>
void main ()
{
int x=!0*10;
a) 10 b) 1 c) 0 d) None of the above.
62 Programming and Data Structures
5) What is the value of 10?
a) 1 b) 0 c) -1 d) None of the above.
6) Hierarchy decides which operator
a) is used first b) is most important
c) operates on large numbers d) None of the above.
7) What will be the value of k after execution of the following program?
# include <stdio.h>
# include <conio.h>
void main()
{
in t k=8;
(k++-k++);
}
a) k=10 b) k=0 c) k=8 d) k=9
8) What will be the value of b after execution of the following program?
void main ()
{
in t b,k=8;
b= (k++-k++-k++#k++);
}
a) b = ll b) b=12 c) b=7 d) b=9
9) The operator displays
a) address of the variable b) value of the variable
c) both (a) and (b) d) none of the above.
10) Addition of two numbers is performed using
a) arithmetic operator b) logical operator
c) unary operator d) comma operator
11) What is the remainer of 8% 10?
a) 8 b) 2 c) 1 d) 0
12) What is the result of the expression (10/3) *3+5%3?
a) 11 b) 10 c) 8 d) 1
13) What is the result of expression (23*2) % (in t) 5. 5?
a) 2 b) 1 c) 3 d) 0
14) What is the result of 16 »2 ?
a) 4 b) 8 c) 2 d) 5
15) What is the result of 5&&2?
a) 0 b) 1 c) 2 d) 5
16) What will be the value of c after execution of the program?
# include <stdio.h>
# include <conio.h>
void main ()
Operators and Expressions 63
{
in t a ,b ,c ;
a=9;
b=10;
c= (b<a | | b>a);
c lr s c r ();
printf (" c=%d",c);
}
OUTPUT:
a) c=l b) c=0 c) c=-l d) none of the above
C) A ttem pt the following programs.
1) Write a program to shift the entered number by three bits left and display the result.
2) Write a program to shift the entered number by five bits right and display the result.
3) Write a program to mask the most significant digit of the entered number. Use AND operator.
4) Write a program to enter two numbers and find the smallest out of them. Use conditional
operator.
5) Write a program to enter a number and carry out modular division operation by 2,3 and 4 and
display the remainders.
6) Attempt the program (5) with division operation and find the quotients.
7) Write a program to enter an integer number and display its equivalent values in octal and
hexadecimal.
8) Write a program to convert hexadecimal to decimal numbers. Enter the numbers such as 0x1 c,
0x18, Oxbc, Oxcd etc.
9) Write a program to find the average temperature of five sunny days. Assume the temperature in
Celsius.
10) Write a program to enter two numbers. Make the comparison between them with conditional
operator. If the first number is greater than second perform multiplication otherwise division
operation.
11) Write a program to calculate the total cost of the vehicle by adding basic cost with a) excise duty
(15%) b) Sales tax (10%) c) Octroi (5%) and d) Road tax (1%). Input the basic cost.
12) Write a program to display ASCII equivalents of
a) 'A ', and ' a ' , ' b ' , ' c ' .
b) 'a '- 'C ' , 'b '-'A ' and 'c ' - ' B ' .
c) xa' + ' c ' , 'b '* 'a ' and 'c'+ 1 2 .
13) Write a program to enter a number that should be less than 100 and greater than 9. Display the
number in reverse order using modular division and division operation
14) Write a program to enter a four-digit number. Display the digits of the number in the reverse
order using modular division and division operation. Perform addition and multiplication of
digits.
15) Write a program to display numbers from 0 to 9. Use ASCII range 48 to 59 and c o n trol s trin g
%c.
16) Write a program to evaluate the following expressions and display their results.
a) x2 +2 x3* (2*x)
b) xl+y2+z3
where, x, y and z are integers.
17) Write a program to print whether the number entered is even or odd use conditional operator?
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.176.99