02 Module2 Important Question
02 Module2 Important Question
On
Principles of Programming using C
Module 2
Operators, Type conversion and Typecasting
1. List all the operators used in C. Give examples
2. Write a note on the following operators. i) Relational ii) Logical iii) Conditional
3. Demonstrate the functioning of Bitwise operator in C
4. What is an assignment operator? Give the different general form of an
assignment statement with an example.
5. Differentiate between typecasting and type conversion. Illustrate with an
example.
6. Give the operator precedence chart.
7. Write a program to calculate salary of an employee, given his basic pay (to be
entered by the user), HRA = 10% of the basic pay, TA = 5% of basic pay. Define
HRA and TA as constants and use them to calculate the salary of the employee.
8. Develop a C program that takes three coefficients (a, b, and c) of a quadratic
equation; (ax2 + bx + c) as input and compute all possible roots and print them
with appropriate messages
9. Convert the following mathematical expression into C equivalent
I. area= s(s-a)(s-b)(s-c)
II. x = -b + b2 -4ac
10. Evaluate the following expression:
I. a + a*b/c-b where a=6, b=3, c=2
II. 100 % 20 < = 20 – 5 + 100 % 10 – 20 = = 5 > = 1! = 20
III. a + = b * = c - = 5 where a=3 b=5 and c=8
IV. (x > y) + ++a ||! c where x=2, y=3, a=4, c=4
V. - -a*(5+b)/2-c++ * b where a=0, b=1, c=-1
11. Find the output of the following codes.
I. #include<stdio.h
> int main ()
{
int x=3, y=5,
z=7; int a, b;
a=x*2+y/5-z*y;
b= ++x * (y- 3) / 2-z++ * y;
printf("\n a = %d", a);
printf("\n b = %d",
b); return 0;
}
II. #include<stdio.h
> int main ()
{
int a=4;
printf("\n %d", 10+a++);
printf("\n b = %d", 10+ +
+a); return 0; }
Decision Control and Looping Statements
1. What are decision control statements? List out all conditional branching
statements supports in C. Explain in detail with syntax and example
2. Explain with syntax, if and if-else statements in C program
3. What is Dangling-else problem. Illustrate with an example.
4. Explain switch statement with syntax. Write a C program to simulate calculator
5. List out what are the advantages of using a switch case statements in C.
6. What are iterative statements? Write a short note on iterative statements that C
language supports with syntax.
7. Explain different types of loops in C with syntax.
8. Give the points of similarity and differences between a while loop and a do-
while loop.
9. Illustrate Nested loops in C with suitable example
10. Explain the working of goto statement in C with an example
11. Show how break and continue statements are used in C program with example.
12. Develop a simple calculator program in C language to do simple operations like
addition, subtraction, multiplication and division. Use switch statement in your
program
13. Write a C program for following:
a. To print whether a given number is palindrome or not.
b. To check whether a given number is even or odd.
c. To find the largest of three numbers using nested if statement.
d. To find the factorial of a number using loops.
e. To find the sum of odd numbers n natural numbers using do-while loop.
14. Write a program to print the following pattern
15. An electricity board charges the following rates for the use of electricity: for the first
200 units 80 paise per unit: for the next 100 units 90 paise per unit: beyond 300 units
Rs 1 per unit. All users are charged a minimum of Rs. 100 as meter charge. If the total
amount is more than Rs 400, then an additional surcharge of 15% of total amount is
charged. Write a program to read the name of the user, number of units consumed and
print out the charges.