0% found this document useful (0 votes)
15 views6 pages

2022 Solve

The document outlines the February 2022 Computer Application Honours exam covering problem solving and programming in C, divided into five units. It includes definitions and explanations of flowcharts, problem-solving approaches, loops, recursion, macros, storage classes, arrays, structures, unions, file modes, and error handling mechanisms. Each section provides examples and code snippets for better understanding of the concepts.

Uploaded by

banishalyngwa99
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)
15 views6 pages

2022 Solve

The document outlines the February 2022 Computer Application Honours exam covering problem solving and programming in C, divided into five units. It includes definitions and explanations of flowcharts, problem-solving approaches, loops, recursion, macros, storage classes, arrays, structures, unions, file modes, and error handling mechanisms. Each section provides examples and code snippets for better understanding of the concepts.

Uploaded by

banishalyngwa99
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

The February 2022 Computer Application Honours (Problem Solving

and Programming in C) exam (BCA-103):

UNIT-I

1. Define a flowchart. Explain the different basic symbols used in flowchart


design.

Answer:
A flowchart is a graphical representation of the flow of an algorithm or process using
symbols. It helps visualize the steps in problem solving.
Common symbols:

 Oval: Start/End

 Rectangle: Process/Instruction

 Parallelogram: Input/Output

 Diamond: Decision (condition)

2. Explain with example the top-down and bottom-up approaches of problem


solving.

Answer:

 Top-down approach: Starts from the main problem and breaks it down into
subproblems step-by-step until reaching simple tasks.

 Bottom-up approach: Starts with designing small modules or subproblems and


integrates them to form the complete solution.

Example: In top-down, a program to calculate area first breaks down into area calculation
functions; in bottom-up, individual functions are implemented first, then combined.

UNIT-II

3. (a) Describe two different ways to use the increment and decrement
operators.
(b) Mention the different rules for naming a variable in C.
(c) Write a program to find the sum of the digits of a number.

Answer:
(a) Increment/decrement operators:

 Prefix (e.g., ++i): increments value before use.

 Postfix (e.g., i++): increments value after use.

(b) Variable naming rules:

 Must start with alphabet or underscore (_).

 Can contain alphabets, digits, and underscore.

 No spaces or special characters allowed.

 Cannot be a keyword or reserved word.

(c) Program to sum digits:

#include <stdio.h>

int main() {
int num, sum = 0, digit;
printf("Enter a number: ");
scanf("%d", &num);

while (num > 0) {


digit = num % 10;
sum += digit;
num /= 10;
}

printf("Sum of digits: %d\n", sum);


return 0;
}

4. (a) What is a loop? Why is it needed in a program? Mention the differences


between a while loop and a do-while loop.
(b) Compare the differences among the following functions: getchar(), getch(),
getche(), gets() and scanf().
Answer:
(a) Loop: Repeats a block of code multiple times. Needed to perform repeated tasks.
Differences:

 while checks condition before the loop body; may execute zero times.

 do-while checks condition after loop body; executes at least once.

(b) Function differences:

 getchar(): Reads a single character, buffered input.

 getch(): Reads a single character without echoing to screen.

 getche(): Reads a single character and echoes it.

 gets(): Reads a string until newline; unsafe due to no length check.

 scanf(): Reads formatted input; can read multiple data types.

UNIT-III

5. (a) What is recursion? Write a program to find the factorial of a number


using recursion.
(b) What is a function call? What is the difference between call by value and
call by reference?

Answer:
(a) Recursion: A function calling itself to solve smaller instances of a problem.
Factorial program:

#include <stdio.h>

int factorial(int n) {
if (n == 0)
return 1;
else
return n * factorial(n - 1);
}

int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);
printf("Factorial of %d is %d\n", num, factorial(num));
return 0;
}

(b) Function call: The process of invoking a function.

 Call by value: Passes a copy of the value; changes inside function do not affect
caller.

 Call by reference: Passes address; changes affect the original variable.

6. (a) What is a macro? Explain with example macro with arguments.


(b) What are command-line arguments in C? What do argv and argc indicate in
command-line arguments? Explain.

Answer:
(a) Macro: Preprocessor directive for code substitution.
Example:

#define SQUARE(x) ((x) * (x))

(b) Command-line arguments are arguments passed to main.

 argc: Argument count (number of arguments including program name).

 argv: Array of strings storing the arguments.

UNIT-IV

7. (a) Explain the different storage classes in C.


(b) What is an array? How are individual array elements identified? Write a C
function to sum the elements of a one-dimensional array.

Answer:
(a) Storage classes:

 auto: Default for local variables.


 register: Suggests storing in CPU register.

 static: Variable retains value between function calls.

 extern: Declares variables defined elsewhere.

(b) Array: Collection of elements of same type; elements identified by index starting 0.
Sum function:

int sumArray(int arr[], int n) {


int sum = 0;
for (int i = 0; i < n; i++)
sum += arr[i];
return sum;
}

8. (a) Explain the concept of passing one function to another. What is meant by
guest function? What is host function?
(b) Briefly explain the relationship between arrays and pointers.

Answer:
(a) Passing function to another: Function pointers are passed as arguments.

 Host function: Function which receives function pointer.

 Guest function: Function passed to another function.

(b) Relationship: An array name behaves like a pointer to its first element; pointer
arithmetic can access array elements.

UNIT-V

9. (a) Distinguish between a structure and a union.


(b) Define enumeration. Write a program to demonstrate the use of
enumeration.

Answer:
(a) Structure: Stores all members separately.
Union: Stores all members at same memory location; only one member valid at a time.
(b) Enumeration defines named integer constants. Example:

#include <stdio.h>

enum color {RED, GREEN, BLUE};

int main() {
enum color c = GREEN;
printf("Value: %d\n", c);
return 0;
}

10. (a) What are the various modes for opening a file? Mention the utility of
each of these modes.
(b) Briefly explain the error handling mechanisms during I/O operations on a
file.

Answer:
(a) File modes:

 "r": Read

 "w": Write (creates new file or truncates)

 "a": Append

 "r+", "w+", "a+": Read and write modes

(b) Error handling: Functions like ferror() check stream errors; feof() checks EOF; use return
values to verify success of I/O functions.

You might also like