0% found this document useful (0 votes)
1 views5 pages

Module 2 Important Questions

The document contains important questions for Module 2 of the Programming for Problem Solving course, covering various C programming topics. Questions include writing programs for series calculations, salary computations, pattern printing, and understanding control statements like if-else and switch-case. Additionally, it addresses concepts such as data types, operator precedence, and error handling in C programming.

Uploaded by

maitynairit
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views5 pages

Module 2 Important Questions

The document contains important questions for Module 2 of the Programming for Problem Solving course, covering various C programming topics. Questions include writing programs for series calculations, salary computations, pattern printing, and understanding control statements like if-else and switch-case. Additionally, it addresses concepts such as data types, operator precedence, and error handling in C programming.

Uploaded by

maitynairit
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Module 2 Important Questions

CSE1001 | Programming for Problem Solving

Prof. Jhalak Dutta Department of CSE [Link]@[Link]


Module 2 Important Questions

1. Write a C program to find the result of the given series up to the nth term, where user will provide the
value of n and x both of which are integers.
x – x3/ 3 + x5 / 5 – x7 / 7 + x9 / 9 + ……….
2. Write a C program to print this pattern (shown for 5 rows here), where the number of rows will be
taken as an input from the user.

3. Consider the weekly salary of a salesperson who is selling some domestic products. If x is the number
of products sold in a week, then the weekly salary is given by the following rules:
4x + 100 for x < 40
Salary = 300 for x = 40
4.5x + 150 for x > 40
(i) Write the if…else statements in C language to represent the above rules.
(ii) Replace the if…else statements written in part (i) above with its equivalent expression
using conditional operator.

4. Suppose you want to write an ‘if’ statement in a C program as follows, where ‘payCode’ is an integer
variable:
if (payCode = = 4)
printf (“\n You get a bonus”);

But by mistake the ‘if’ statement is written as follows:


if (payCode = 4)
printf (“\n You get a bonus”);

Do you get the same result for this mistake? Give reasons against your answer.
5. Write a C program to print the following pattern (shown here for 5 rows) where the number of rows
in the pattern is a user input. You may assume that the number of rows is odd.

6. A perfect number is a positive number in which sum of all positive divisors excluding that number is
equal to that number. Write a C program that accepts a number from the user and checks whether it
is a perfect number. (If the number entered by the user is not positive, your program should show
an error message and ask user to input a number again)

Prof. Jhalak Dutta | Assistant Professor | Department of CSE |[Link]@[Link] 1


Module 2 Important Questions

7. Write a C program that accepts an integer from the user and prints the next five prime numbers in
sequence. For example:
Input: 10
Output: 11 13 17 19 23

8. Justify the following statement: “the range of signed char (1 byte) is -128 to +127”.

9. Explain the output or error of the following snippets of code:

(i)

(ii)

(iii)

Prof. Jhalak Dutta | Assistant Professor | Department of CSE |[Link]@[Link] 2


Module 2 Important Questions

10. Write a C program to print the following pattern (shown here for 6 rows) where the number of
rows in the pattern is a user input:

11. “Switch case is not always a replacement of if-else statement” – Justify this statement.
12. Write a C program to find out the minimum number of currency notes of denomination 500, 200,
100, 50, 20, 10, 5, 2, and 1 to be issued to pay a particular amount entered by the user. Hint: Using
an array to access the given values will reduce the length of your program.
13. How does the continue statement different from break in loops? What happens if continue is used
inside a do-while loop? Explain your answer with code snippet.

14. Explain the difference between x++ and ++x in detail, including how they affect expressions and
function arguments. Give code example to explain your answer.
15. Write a C program to find out the sum of the following series up to n terms where n and x values are
integers which should be taken from the user as input. You are not allowed to use any built-in
function such as pow() from the math.h library.

𝑥 𝑥3 𝑥5 𝑥7
𝑆= − + − + ⋯ 𝑢𝑝𝑡𝑜 𝑛𝑡ℎ 𝑡𝑒𝑟𝑚
2 4 8 16

16. Write a C program to print the following pattern (shown here for 5 rows). The user should input the
number of rows. If the entered number is not an odd number, the program should prompt the user
to enter it again. The user is allowed up to three attempts to provide a valid odd number. If all three
attempts fail, the program should terminate.

Prof. Jhalak Dutta | Assistant Professor | Department of CSE |[Link]@[Link] 3


Module 2 Important Questions

17. What will be the output of the following C code? Explain your answer.

18. Write a C program to find the maximum of 3 numbers using only ternary operator. Input all 3
numbers from the users.
19. Rewrite the following code snippet using only do...while loop in such a way that the output will
remain same.

20. What is the different bit-wise operators in C? Explain their functionalities using code examples.
21. Explain the difference between implicit type conversion and explicit type casting in C. Write a C
program to demonstrate both.
22. Differentiate between relational operators and logical operators in C. Write a small program to
show how logical AND (&&) and logical OR (||) affect decision making.
23. Compare nested if-else and switch-case statements. In which situations is nested if more suitable?
Explain with example program.
24. Explain the difference between local and global variables in C. Write a program to demonstrate how
variable scope works.
25. What is an infinite loop? Write three different examples of infinite loops using for, while, and do-
while.
26. Differentiate between break and return statements in C with examples. What happens if return is
used inside a loop?
27. Write a C program to accept an integer from the user and check whether the input is valid numeric
input (use scanf return value). Explain how validation works.
28. Explain operator precedence and associativity in C. What will be the output of the following
expression? Justify your answer:

int x = 5, y = 10, z = 2;
int result = x + y * z > 20 && z++;
printf("%d %d", result, z);

29. What is short-circuit evaluation in C? Explain with an example involving logical operators and
increment operators.
30. Write a C program to print the size (in bytes) of all basic data types using sizeof operator. Explain
why size may vary across systems.

Prof. Jhalak Dutta | Assistant Professor | Department of CSE |[Link]@[Link] 4

You might also like