C Programming Laboratory Manual — 20 Practical Programs with Output
Official practical laboratory manual containing 20 complete C programming experiments, source codes, flowcharts, and verified outputs for TU BCA.
C Programming Laboratory Manual — 20 Practical Programs with Output
TU · BCA · C Programming
C Programming Laboratory Work Book & Manual
Course Code: CACS101 | Practical Credit: 2 Credits (Full Marks: 40, Pass Marks: 16)
Table of Contents (20 Verified Experiments)
- Lab 01: Basic I/O, Arithmetic Operations and Formatting Specifiers
- Lab 02: Conditional Statements (Largest of 3 numbers using nested if-else)
- Lab 03: Menu-Driven Calculator using Switch-Case Statement
- Lab 04: Fibonacci Series Generation using For and While Loops
- Lab 05: Prime Number Verification and Range Generation
- Lab 06: Sum and Reverse of Digits of an Integer
- Lab 07: 1D Array Input, Sorting (Bubble Sort), and Searching
- Lab 08: Matrix Addition and Subtraction of Order M x N
- Lab 09: Matrix Multiplication with Dimensional Compatibility Check
- Lab 10: String Operations without String Library Functions (strlen, strcpy, strcat, strrev)
- Lab 11: Palindrome String Verification using Character Arrays
- Lab 12: Swap Two Numbers using Call by Value vs Call by Reference (Pointers)
- Lab 13: Factorial Calculation using Recursive Functions
- Lab 14: Greatest Common Divisor (GCD) using Euclids Algorithm
- Lab 15: Dynamic Memory Allocation for 1D Array using
malloc()andfree() - Lab 16: Student Record Management using Structures (Name, Roll, Marks, Percentage)
- Lab 17: Array of Structures Sorting by Student Roll Number
- Lab 18: Writing and Reading Formatted Data to a Sequential Text File (
fprintfandfscanf) - Lab 19: Copying Contents of One File to Another Character by Character (
fgetcandfputc) - Lab 20: Binary Record Storage and Retrieval using
fwrite()andfread()
Selected Featured Lab Implementation: Lab 09 (Matrix Multiplication)
```c #include <stdio.h>
int main() { int r1, c1, r2, c2; int a[10][10], b[10][10], c[10][10];
printf("Enter rows and columns for First Matrix: "); scanf("%d %d", &r1, &c1); printf("Enter rows and columns for Second Matrix: "); scanf("%d %d", &r2, &c2);
if (c1 != r2) { printf("Error: Matrix multiplication not possible! Columns of A (%d) != Rows of B (%d)\n", c1, r2); return 1; }
printf("\nEnter elements of Matrix A:\n"); for (int i = 0; i < r1; i++) { for (int j = 0; j < c1; j++) { scanf("%d", &a[i][j]); } }
printf("\nEnter elements of Matrix B:\n"); for (int i = 0; i < r2; i++) { for (int j = 0; j < c2; j++) { scanf("%d", &b[i][j]); } }
// Multiply matrices: c[i][j] = sum(a[i][k] b[k][j]) for (int i = 0; i < r1; i++) { for (int j = 0; j < c2; j++) { c[i][j] = 0; for (int k = 0; k < c1; k++) { c[i][j] += a[i][k] b[k][j]; } } }
printf("\nProduct Matrix (Resultant %d x %d):\n", r1, c2); for (int i = 0; i < r1; i++) { for (int j = 0; j < c2; j++) { printf("%4d ", c[i][j]); } printf("\n"); }
return 0; } ```
Sample Output:
```text Enter rows and columns for First Matrix: 2 3 Enter rows and columns for Second Matrix: 3 2
Enter elements of Matrix A: 1 2 3 4 5 6
Enter elements of Matrix B: 7 8 9 1 2 3
Product Matrix (Resultant 2 x 2): 31 19 85 55 ```
