Fundamentals of Programming Using C - Model Question Paper Solutions (Detailed)
Part A: Very Short Answer Questions
1. Steps in the Program Development Life Cycle:
- Analysis: Understand the problem requirements.
- Design: Plan the solution (e.g., flowcharts, pseudocode).
- Coding: Write the program using a programming language.
- Testing: Ensure the program functions correctly.
- Implementation: Deploy the program.
- Maintenance: Update and fix issues over time.
2. Types of Language Translators:
- Assembler: Converts assembly language to machine code.
- Compiler: Converts high-level language to machine code (e.g., gcc for C).
- Interpreter: Executes code line-by-line (e.g., Python interpreter).
3. Difference Between Expression and Statement in C:
- Expression: Produces a value (e.g., `a + b`).
- Statement: Performs an action (e.g., `x = a + b;`).
4. Example of a Do-While Loop in C:
```c
#include <stdio.h>
int main() {
int num;
do {
printf("Enter a positive number: ");
scanf("%d", &num);
} while (num <= 0);
return 0;
```
5. ASCII Value Ranges:
- Uppercase Letters: 65 to 90.
- Lowercase Letters: 97 to 122.
6. Purpose of Continue Statement in C:
- Skips the rest of the code in the current loop iteration and proceeds to the next iteration.
7. Computing Total Cost of Items in an Array:
```c
#include <stdio.h>
int main() {
float prices[] = {10.5, 20.3, 5.7};
int n = sizeof(prices) / sizeof(prices[0]);
float total = 0;
for (int i = 0; i < n; i++) {
total += prices[i];
printf("Total cost: %.2f", total);
return 0;
}
```
8. Analyzing Output of printf:
```c
float num = 45.6789;
printf("%.2f", num); // Output: 45.68
```
9. Declaring and Calling a Function:
```c
#include <stdio.h>
int add(int a, int b); // Function declaration
int main() {
int result = add(3, 4);
printf("Sum: %d", result);
return 0;
int add(int a, int b) {
return a + b; // Function definition
```
10. Difference Between Struct and Union:
- **Struct:** All members occupy separate memory locations.
- **Union:** All members share the same memory location.
Part B: Short Answer Questions
11. Debugging in C:
- Steps: Identify, Isolate, Fix, Test.
- Tools: GDB for runtime errors, syntax highlighting for syntax errors.
12. Operator Precedence Example:
```c
int result = 10 + 5 * 2; // Multiplication is evaluated first.
printf("%d", result); // Output: 20
```
13. Importance of Delimiters:
- Define structure (e.g., `{}` for blocks, `;` for statements).
14. Read and Display User Input:
```c
#include <stdio.h>
int main() {
char name[50];
int age;
printf("Enter name: ");
scanf("%s", name);
printf("Enter age: ");
scanf("%d", &age);
printf("Name: %s, Age: %d
", name, age);
return 0;
```
15. Fibonacci Using Recursion:
```c
int fibonacci(int n) {
if (n <= 1) return n;
return fibonacci(n - 1) + fibonacci(n - 2);
```
Part C: Essay Questions
18. Comparing If-Else and If-Else-If Ladder:
```c
if (x > 0) printf("Positive");
else if (x < 0) printf("Negative");
else printf("Zero");
```
19. Storage Classes in C:
- **Auto:** Default local scope.
- **Static:** Persistent values.
- **Extern:** Global access across files.
- **Register:** Faster access in CPU registers.
20. Function Concepts:
- Declaration: `int add(int, int);`
- Definition: Implements logic.
- Call: `add(3, 4);`