BCS101 / BCS201 : Programming for Problem Solving
-----------------------------------------------
UNIT-1 : INTRODUCTION TO COMPUTER SYSTEM
(Topics)
1. Components of a computer: CPU (Processor), Memory (RAM, ROM), I/O Devices, Secondary storage.
2. Operating System: Role, examples (Windows, Linux), basic functions.
3. Language Translators: Assembler, Compiler, Interpreter, Loader, Linker — क्या करते हैं।
4. Algorithm: परिभाषा, Flowchart, Pseudocode, Code with Examples.
5. Programming Basics: Structure of a C program, Compilation, Executable.
6. First C Program: Syntax and common logical errors.
Example: Simple C program (Hello & reading input)
```c
#include <stdio.h>
int main() {
// Print and read an integer
printf("Enter a number: ");
int n;
if (scanf("%d", &n) != 1) {
printf("Input error\n");
return 1;
}
printf("You entered: %d\n", n);
return 0;
}
```
UNIT-2 : ARITHMETIC EXPRESSIONS
(Topics)
1. Arithmetic expressions and precedence of operators.
2. Using numeric and relational operators, logical operators, bitwise operators.
3. Mixed operands, type conversion.
4. Assignment operators, operator precedence and associativity.
5. Conditional branching: if, if-else, nested if, switch-case.
Example: Demonstrate precedence and conversion
```c
#include <stdio.h>
int main() {
int a = 5, b = 2;
double x = a / b; // integer division -> 2
double y = (double)a / b; // -> 2.5
printf("a/b (int) = %f\n", x);
printf("a/b (double) = %f\n", y);
int val = 10;
if (val > 0 && val < 100) {
printf("val is between 1 and 99\n");
} else {
printf("out of range\n");
}
return 0;
}
```
UNIT-3 : ITERATION & LOOPS
(Topics)
1. Loops: while, do-while, for.
2. Loop variables, using break, continue, goto.
3. Arrays: single and multi-dimensional, array notation, manipulating arrays.
4. Strings, structures, union (brief), enum, passing arrays to functions.
Examples:
a) For loop and break/continue
```c
#include <stdio.h>
int main() {
for (int i = 1; i <= 10; i++) {
if (i % 2 == 0) continue; // skip even
if (i > 7) break; // stop when >7
printf("%d ", i);
}
printf("\n");
return 0;
}
```
b) Array basics and sum
```c
#include <stdio.h>
int main() {
int arr[] = {3, 5, 7, 2, 9};
int n = sizeof(arr)/sizeof(arr[0]);
int sum = 0;
for (int i = 0; i < n; i++) sum += arr[i];
printf("Sum = %d\n", sum);
return 0;
}
```
UNIT-4 : FUNCTIONS
(Topics)
1. Function introduction, types, functions with arrays.
2. Passing parameters: call by value, call by reference (using pointers).
3. Recursive functions.
4. Basic searching and sorting algorithms:
- Linear Search
- Binary Search (on sorted array)
- Bubble Sort
- Insertion Sort
- Selection Sort
Examples:
a) Function (call by value) and recursion (factorial)
```c
#include <stdio.h>
int factorial(int n) {
if (n <= 1) return 1;
return n * factorial(n - 1);
}
int main() {
int num = 5;
printf("Fact(%d) = %d\n", num, factorial(num));
return 0;
}
```
b) Linear search and binary search
```c
#include <stdio.h>
int linear_search(int a[], int n, int key) {
for (int i=0; i<n; i++) if (a[i] == key) return i;
return -1;
}
int binary_search(int a[], int n, int key) {
int lo = 0, hi = n-1;
while (lo <= hi) {
int mid = lo + (hi-lo)/2;
if (a[mid] == key) return mid;
else if (a[mid] < key) lo = mid + 1;
else hi = mid - 1;
}
return -1;
}
int main() {
int a[] = {1,2,4,6,8,9};
int idx = binary_search(a, 6, 6);
printf("Index = %d\n", idx);
return 0;
}
```
c) Bubble sort
```c
#include <stdio.h>
void bubble_sort(int a[], int n) {
for (int i=0; i<n-1; i++)
for (int j=0; j<n-1-i; j++)
if (a[j] > a[j+1]) {
int t = a[j]; a[j] = a[j+1]; a[j+1] = t;
}
}
int main() {
int a[] = {5,2,9,1,5,6};
int n = sizeof(a)/sizeof(a[0]);
bubble_sort(a, n);
for (int i=0; i<n; i++) printf("%d ", a[i]);
printf("\n");
return 0;
}
```
UNIT-5 : POINTERS
(Topics)
1. Pointers: introduction, declaration, use.
2. Dynamic memory allocation (malloc, calloc, realloc, free).
3. Pointer arithmetic, pointers and arrays.
4. String functions (strlen, strcpy, strcat, strcmp) — use <string.h>.
5. Use of pointers in self-referential structures (linked lists) — concept; No full implementation
required unless requested.
6. File handling: fopen, fclose, fprintf, fscanf, fread, fwrite, fseek, ftell.
7. Standard C preprocessor, macros, command-line arguments.
Examples:
a) Pointer basics
```c
#include <stdio.h>
int main() {
int x = 10;
int *p = &x;
printf("x=%d, *p=%d\n", x, *p);
*p = 20;
printf("x now=%d\n", x);
return 0;
}
```
b) Dynamic allocation example
```c
#include <stdio.h>
#include <stdlib.h>
int main() {
int n = 5;
int *arr = (int*) malloc(n * sizeof(int));
if (!arr) return 1;
for (int i=0; i<n; i++) arr[i] = i*i;
for (int i=0; i<n; i++) printf("%d ", arr[i]);
printf("\n");
free(arr);
return 0;
}
```
c) Simple file I/O
```c
#include <stdio.h>
int main() {
FILE *f = fopen("[Link]", "w");
if (!f) { perror("fopen"); return 1; }
fprintf(f, "Hello file\n");
fclose(f);
return 0;
}
```
SHORT QUESTIONS & SOLVED PAPERS
- Short question practice: define keywords, write small programs, explain differences (compiler vs
interpreter), explain operator precedence, output of small code fragments.
- Solved papers (2017-18 to 2024-25): practice previous year questions; attempt writing full
programs and dry-run.
----
Notes:
- ऊपर दिए गए कोड C भाषा में हैं। इन्हें चलाने के लिए gcc या किसी C compiler का उपयोग करें:
gcc program.c -o program
./program
- अगर आप चाहें तो मैं हर टॉपिक के लिए और विस्तृत उदाहरण और प्रयोगात्मक प्रश्न (practice problems) दे
सकता हूँ।