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:
| 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 |
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");
}
Basic Data Types:
int (2 or 4 bytes) - Integersfloat (4 bytes) - Decimal numberschar (1 byte) - Charactersdouble (8 bytes) - High precision decimalsOperators: = is assignment, == is comparison. & is
bitwise AND, && is logical AND.
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);
}
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.
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++;
Employee Structure:
struct Employee {
int id;
char name[50];
float salary;
};
// In main:
struct Employee emp[10];
// Loop to input and check salary > 50000
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);
}
Problem: Read employees, filter by department & salary, sort, write to file.
Logic:
struct Employee.fread or fscanf to load data into an array of structures.if(strcmp(e[i].dept, "Sales")==0 && e[i].salary > 50000).fprintf.Problem: Read 3 files (Physics, Chem, Maths), calculate %, grade, write result.
Logic:
sum = p + c + m; percent = sum/3.0;Problem: Issue books, calculate fine.
Logic:
struct Book { int id; char title[50]; int issued_flag; char date[20]; }if(b.issued_flag == 0) then set to 1.if(days > 15) fine = (days-15) * 5;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.
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).
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).
Block Diagram of Computer: Input Unit -> CPU (ALU + CU + Memory) -> Output Unit.
Compilation Process: Source Code -> Preprocessor -> Compiler -> Assembler -> Linker -> Executable.
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].
Syntax: int main(int argc, char *argv[])
Sum of numbers:
int sum = 0;
for(int i=1; i
Storage Classes:
Factorial: See Recursion section.
Macro vs Function: Macro is preprocessed (text replacement, faster, no type checking). Function is compiled (stack overhead, type checking).
Palindrome: See Strings section.
Matrix Mult: See Arrays section.
CLA Sum: See Command Line Arguments section.
Problem: Book structure with functions.
Logic:
void display(struct Book b[], int n).a = a + b;
b = a - b;
a = a - b;
Sum of digits raised to power of number of digits.
while(temp!=0) { rem=temp%10; sum+=pow(rem,n); temp/=10; }
See Section B recursion example.
See Section B arrays example.
See Section B strings example.
See Section B file handling example.
See Section B structure example.
Structure: Separate memory for each member. Size = Sum of members.
Union: Shared memory. Size = Largest member.