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

C Programming Problem-Solving Practice Set

The document is an ETE practice set for a programming course focused on problem-solving using C. It includes sections on concepts and theory, programs and algorithms, arrays, functions and pointers, strings and files, and advanced concepts with case studies. Each section contains various questions and programming tasks designed to help students prepare for their exams by understanding key concepts and practicing coding skills.

Uploaded by

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

C Programming Problem-Solving Practice Set

The document is an ETE practice set for a programming course focused on problem-solving using C. It includes sections on concepts and theory, programs and algorithms, arrays, functions and pointers, strings and files, and advanced concepts with case studies. Each section contains various questions and programming tasks designed to help students prepare for their exams by understanding key concepts and practicing coding skills.

Uploaded by

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

ETE PRACTICE SET

Subject: Programming for Problem-Solving using C


Course Code: R1UC101B
(Note to Students: The questions provided in this question bank are reference questions designed
to help you understand the pattern, level, and type of questions you may encounter in your exams.
Please note: The same questions may not appear in the exam. However, you can expect similar
questions based on the concepts and formats practiced here. Focus on understanding each topic's
logic, syntax, and theory for best preparation.)

Section A – Concepts & Theory


1. Define a flowchart. List and explain any five common flowchart symbols. Draw a
flowchart to check whether a given number is positive or negative.
2. Explain the difference between logical operators and relational operators in C with
suitable examples.
3. Define Algorithm and differentiate between pseudocodes in C programming.
4. Which member decides the memory size of a union?
5. What are header files? Explain the role of library functions, preprocessor, compiler,
and interpreter in program execution.
6. Describe the basic structure of a C program with a neat diagram or example.
7. Explain the working of nested if–else statements with a suitable illustration.
8. What are entry-controlled and exit-controlled loops? Give one example for each and
write two differences.
9. Explain the purpose of the switch–case statement. Mention any four limitations of switch–
case in C.
10. What is the dangling else problem in C? Why does it occur in nested if statements?
Explain how using braces { } solves the problem with an example.
11. What are bitwise operators? Explain their use and precedence with a simple example.
12. Explain the importance of storage classes in C. Why are they required?
13. Identify the output of the following expression:
int result = 10 + 4 * 3 - 8 / 2;

Section B – Programs & Algorithms


14. Write a C program to print the multiplication table of a number entered by the user.
15. Write an algorithm and draw a flowchart to find the smallest of three numbers.

16. Write a C program to display the following pattern:


1. B)
1 *
12 **
123 ***
1234 ****
17. Write an algorithm and C program to print the Fibonacci series up to a maximum value of
50.

18. Explain the difference in memory usage between structure and union with an example.
19. Write a C program using switch–case to check whether a given character is a vowel or
consonant.
20. Write a C program using nested if–else to check whether a number is even, odd, or zero.
21. Write a program to print one value each of int, float, char, and double, along with their
format specifiers.
22. Write a program using switch–case to perform basic arithmetic operations based on user
choice.
23. Write a program to check whether a number is divisible by 7 but not by 4, and also a
multiple of 6.
24. Write a C program using if–else-if ladder to display grades based on percentage.
Section C – Arrays, Functions & Pointers
25. Explain call by value and call by address with simple C programs.
26. Define one-dimensional and two-dimensional arrays. Write a program to find the sum
of all elements in a 2D array.
27. Write a C program using functions to:
 Find the maximum element
 Find the minimum element
 Find the average of array elements
28. Explain how arrays are passed to functions. What happens to array name when passed as
a parameter?
29. Write a program to find the largest and smallest elements in an array entered by the user.
30. Explain the concept of pointers. Describe pointer declaration, initialization, and
dereferencing with an example.
31. Differentiate between NULL pointer and dangling pointer with examples.

Section D – Strings & Files


32. Explain the use of strlen(), strcpy(), and strcat() with examples.
33. Write a C program to reverse a string without using library functions.
34. Explain NULL termination in strings. How is it important?
35. Write a program to input employee names and:
 Count names starting with consonants
 Convert names to lowercase
36. Differentiate between a string and a character array.
37. Write a C program to read data from [Link] and display values greater than a given
number.
38. Explain how fscanf() handles whitespace while reading strings from a file.

Section E – Advanced Concepts & Case Studies


39. Explain static and dynamic memory allocation. List four differences between them.
40. Write a code snippet using malloc() and calloc() and explain the difference.
41. A parking system has a fixed number of slots normally, but during events the slots increase
dynamically.
 Identify suitable memory allocation methods.
 Justify your answer.
42. Define structures, unions, and enum with examples. When is a union preferred?
43. Write a program using macros to calculate simple interest. Explain advantages of macros.
44. A result processing system uses:
 Structures for student details
 Enum for grade
 Union for marks or grade
 File handling to store results
Explain how these features improve program design.
45. Case 1: Employee Attendance Management System

An organization stores daily attendance (present = 1, absent = 0) of employees in an array.


The data needs to be analyzed efficiently.

Questions:

a) Why is an array suitable for storing attendance data in this scenario?


b) Write a C program using pointers to count the total number of present and absent
employees.
c) How does pointer arithmetic help in traversing the attendance array?
d) What happens if the pointer moves beyond the allocated array size?

46. Case 2: Online Examination Result Processing

An online examination system stores marks of students in an integer array. The system
also stores student names as strings.

Questions:

a) Explain how arrays and strings are stored in memory.


b) Write a C program using pointers to calculate the average marks of students.
c) Use pointer notation to display student names without using array indexing.
d) Identify possible errors if string input exceeds allocated array size.

47. Differentiate between gets() and fgets().

48. Differentiate between syntax error and logical error.

[Link]: Dynamic Marks Allocation (Dynamic Memory Allocation)

A faculty wants to store marks of students dynamically based on the number of students.

Tasks:
a) Explain why dynamic memory allocation is required.
b) Write a program using malloc() to allocate memory for marks.
c) Calculate and display the average marks.
d) What happens if free() is not used?

50. Case: Preprocessor Based Calculation (Macros)

A program needs reusable logic for arithmetic operations.

Tasks:
a) Define macros for ADD, SUB, and MUL operations.
b) Write a program using macros to perform calculations.
c) Explain one advantage of using macros.
d) State one limitation of macros.

Common questions

Powered by AI

Macros in C provide several advantages like avoiding repetitive code, enhancing readability, and allowing code expansion without function call overhead. However, they have limitations such as lack of type safety, no scope, unexpected expansions resulting in errors, and debugging difficulties. In arithmetic operations, macros can simplify expressions (e.g., ADD(a, b) for a+b), but their expanded code can lead to issues if operands have side effects or are complex expressions .

Static memory allocation in C occurs at compile-time, with fixed size and lifetime, suitable for arrays and variables whose size doesn't change. Dynamic allocation happens at runtime using functions like malloc(), allowing flexible memory use based on current needs. Four differences include: 1) Static is fixed; dynamic is variable. 2) Static does not use pointers; dynamic primarily involves pointers. 3) Static memory is managed by the system; dynamic requires programmer control with malloc()/free(). 4) Static is typically faster due to predetermined size, whereas dynamic can incur overhead due to runtime allocation .

In C, a string is a sequence of characters ending with a null character '\0', while a character array is an array whose elements are characters. Strings, being null-terminated, facilitate various manipulations using standard library functions like strlen(), strcpy(), and strcat(), which are aware of the termination. Character arrays do not inherently have such capabilities unless explicitly null-terminated. These differences impact operations, memory management, and error handling (e.g., buffer overflows) in string manipulation tasks .

A switch-case statement in C is used to execute one block of code among multiple options based on the value of a variable. It's particularly useful for menu-driven programs and handling character inputs. However, its limitations include: inability to handle ranges directly, lack of support for strings or floating-point comparisons, inherent fall-through behavior without break statements, and sometimes requiring a default case for completeness. These constraints can limit its flexibility compared to a series of if-else statements .

Dynamic memory allocation in C is crucial because it allows the allocation of memory at runtime, accommodating applications where the amount of data can vary, like when the number of inputs isn't fixed. This permits efficient memory utilization, prevents wastage, and facilitates flexible data structures such as linked lists or resizable arrays. Functions like malloc() and calloc() enable dynamic management, but programmers must also manage memory deallocation with free() to prevent leaks .

The dangling else problem in C occurs in nested if statements when an else clause is ambiguously associated with the nearest if without an explicit match. It leads to confusion about which if the else part belongs to. This issue can be resolved by using braces to clearly define the block of code that each if corresponds with. For example, using if (condition) { if (another_condition) { ... } } else { ... } ensures the else is associated with the outer if statement .

Pointer arithmetic allows for direct manipulation of memory addresses, thereby facilitating efficient array traversal by incrementing pointers to access elements sequentially. This approach often enhances execution speed as it bypasses the use of index variables. However, improper pointer arithmetic, such as incrementing pointers beyond the array size, can lead to accessing harmful memory regions, causing undefined behavior, potential segmentation faults, or corruption of data, highlighting the need for cautious pointer use .

In C, call by value passes a copy of the argument's value to the function, meaning changes made inside the function don't affect the original variable. Conversely, call by address passes the address of the argument, allowing the function to modify the variable's actual value. Call by value is safer as it prevents unintended side effects, whereas call by address offers more flexibility for modifying large data structures directly, enabling efficient memory use .

Storage classes in C define the scope, visibility, and lifetime of variables. They play a crucial role in determining where variables can be accessed and how long they persist during program execution. The four primary storage classes are auto, register, static, and extern. Understanding them is essential as it affects memory management, speed optimization (register), and variable persistence across function calls (static). They help programmers manage resources efficiently and control data sharing across files using extern .

Logical operators in C (&&, ||, !) are used to combine multiple conditions, returning true or false values based on logical conjunction or disjunction. For instance, the expression (a > b && c < d) checks whether both conditions are true. Relational operators (==, !=, >, <, >=, <=) compare two values or expressions, yielding a boolean result based on the relation. For example, a > b checks if 'a' is greater than 'b'. Their usage differs as logical operators often combine results of relational expressions to form complex conditions .

You might also like