← Back to Guide

Comprehensive Solutions Guide

Table of Contents

SECTION A: Basic Concepts

1. Von Neumann Architecture

Concept: The Von Neumann architecture describes a computer architecture based on the stored-program computer concept, where instruction data and program data are stored in the same memory.

Key Components:

2. System vs Application Software

Feature System Software Application Software
Purpose Manage system resources Perform specific user tasks
Example OS (Windows, Linux), Drivers Word, Chrome, Games
Dependency Independent Depends on System Software

3. Control Structures (if-else vs switch)

if-else: Used for ranges of values or boolean conditions. Checks conditions sequentially.

switch-case: Used for discrete values (int, char). Jumps directly to the matching case (faster for many conditions).

// Switch Example
switch(choice) {
    case 1: printf("One"); break;
    case 2: printf("Two"); break;
    default: printf("Invalid");
}

4. C Basics & Data Types

Basic Data Types:

Operators: = is assignment, == is comparison. & is bitwise AND, && is logical AND.

SECTION B: Core Programming

1. Recursion Examples

Factorial:

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

Fibonacci:

int fib(int n) {
    if(n<=1) return n;
    return fib(n-1) + fib(n-2);
}

GCD:

int gcd(int a, int b) {
    if(b==0) return a;
    return gcd(b, a%b);
}

2. Arrays & Matrices

Matrix Multiplication (3x3):

for(i=0; i<3; i++) {
    for(j=0; j<3; j++) {
        res[i][j] = 0;
        for(k=0; k<3; k++)
            res[i][j] += a[i][k] * b[k][j];
    }
}

Transpose: trans[j][i] = mat[i][j];

Linear Search: Loop through array, if arr[i] == key, return index.

3. String Operations (Manual)

Palindrome Check:

int isPalindrome(char str[]) {
    int l = 0, h = strlen(str) - 1;
    while(h > l) {
        if(str[l++] != str[h--]) return 0;
    }
    return 1;
}

String Length: while(str[i] != '\0') i++;

4. Structures

Employee Structure:

struct Employee {
    int id;
    char name[50];
    float salary;
};
// In main:
struct Employee emp[10];
// Loop to input and check salary > 50000

5. File Handling

Even/Odd Separation:

FILE *f1 = fopen("input.txt", "r");
FILE *fe = fopen("even.txt", "w");
FILE *fo = fopen("odd.txt", "w");
while(fscanf(f1, "%d", &num) != EOF) {
    if(num%2==0) fprintf(fe, "%d\n", num);
    else fprintf(fo, "%d\n", num);
}

SECTION C: Advanced Problems

Type 1: Employee File Processing

Problem: Read employees, filter by department & salary, sort, write to file.

Logic:

  1. Define struct Employee.
  2. Use fread or fscanf to load data into an array of structures.
  3. Loop to filter: if(strcmp(e[i].dept, "Sales")==0 && e[i].salary > 50000).
  4. Sort using Bubble Sort on the filtered array based on date.
  5. Write result using fprintf.

Type 2: Student Marks Processing

Problem: Read 3 files (Physics, Chem, Maths), calculate %, grade, write result.

Logic:

  1. Open all 3 input files and 1 output file.
  2. Loop while all files have data.
  3. sum = p + c + m; percent = sum/3.0;
  4. Determine grade using if-else ladder.
  5. Write to output file.

Type 4: Library Management

Problem: Issue books, calculate fine.

Logic:

  1. struct Book { int id; char title[50]; int issued_flag; char date[20]; }
  2. Issue Function: Check if(b.issued_flag == 0) then set to 1.
  3. Fine Function: Calculate days difference. if(days > 15) fine = (days-15) * 5;

Section A: 1. Number System Conversions

Binary to Decimal: Multiply each bit by 2^n. Ex: 101 = 1*4 + 0*2 + 1*1 = 5.

Decimal to Binary: Divide by 2 and record remainders. Ex: 5/2=2(1), 2/2=1(0), 1/2=0(1) -> 101.

Hexadecimal: Base 16 (0-9, A-F). 1 Hex digit = 4 Binary bits.

Section A: 2. Differentiate Between

Compiler vs Interpreter: Compiler translates whole code (faster execution), Interpreter translates line-by-line (easier debugging).

Structure vs Union: Structure has separate memory for members, Union shares memory.

while vs do-while: while checks condition first (entry controlled), do-while executes at least once (exit controlled).

Section A: 3. Basic C Programs

Prime Number: Loop from 2 to n/2, if n%i==0 then not prime.

Armstrong: Sum of cubes of digits == number.

Fibonacci: 0, 1, 1, 2, 3... (next = prev + curr).

Section A: 4. Explain with Diagram

Block Diagram of Computer: Input Unit -> CPU (ALU + CU + Memory) -> Output Unit.

Compilation Process: Source Code -> Preprocessor -> Compiler -> Assembler -> Linker -> Executable.

Section B: Category 6: Pointers

Swap using Pointers:

void swap(int *a, int *b) {
    int temp = *a;
    *a = *b;
    *b = temp;
}

Array Access: *(arr + i) is same as arr[i].

Section B: Category 7: Command Line Arguments

Syntax: int main(int argc, char *argv[])

Sum of numbers:

int sum = 0;
for(int i=1; i

Predicted Q1: Storage Classes & Factorial

Storage Classes:

Factorial: See Recursion section.

Predicted Q2: Palindrome & Macro vs Function

Macro vs Function: Macro is preprocessed (text replacement, faster, no type checking). Function is compiled (stack overhead, type checking).

Palindrome: See Strings section.

Predicted Q3: Matrix & CLA

Matrix Mult: See Arrays section.

CLA Sum: See Command Line Arguments section.

Section C: Type 3: Complex String/Structure

Problem: Book structure with functions.

Logic:

  1. Pass array of structures to function: void display(struct Book b[], int n).
  2. Loop through array to find max price or pages > 300.
  3. Return result or print inside function.

Practice Questions (Detailed)

Q1: Swap Two Numbers

a = a + b;
b = a - b;
a = a - b;

Q2: Armstrong Number

Sum of digits raised to power of number of digits.

while(temp!=0) { rem=temp%10; sum+=pow(rem,n); temp/=10; }

Q3: Factorial (Recursive)

See Section B recursion example.

Q4: Matrix Multiplication

See Section B arrays example.

Q5: Palindrome

See Section B strings example.

Q6: File Handling

See Section B file handling example.

Q7: Employee Structure

See Section B structure example.

Q8: Structure vs Union

Structure: Separate memory for each member. Size = Sum of members.

Union: Shared memory. Size = Largest member.