Nepal's open education portal

EduNepalEduNepal

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.

Verified Lab ManualCACS101· TU

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)

  1. Lab 01: Basic I/O, Arithmetic Operations and Formatting Specifiers
  2. Lab 02: Conditional Statements (Largest of 3 numbers using nested if-else)
  3. Lab 03: Menu-Driven Calculator using Switch-Case Statement
  4. Lab 04: Fibonacci Series Generation using For and While Loops
  5. Lab 05: Prime Number Verification and Range Generation
  6. Lab 06: Sum and Reverse of Digits of an Integer
  7. Lab 07: 1D Array Input, Sorting (Bubble Sort), and Searching
  8. Lab 08: Matrix Addition and Subtraction of Order M x N
  9. Lab 09: Matrix Multiplication with Dimensional Compatibility Check
  10. Lab 10: String Operations without String Library Functions (strlen, strcpy, strcat, strrev)
  11. Lab 11: Palindrome String Verification using Character Arrays
  12. Lab 12: Swap Two Numbers using Call by Value vs Call by Reference (Pointers)
  13. Lab 13: Factorial Calculation using Recursive Functions
  14. Lab 14: Greatest Common Divisor (GCD) using Euclids Algorithm
  15. Lab 15: Dynamic Memory Allocation for 1D Array using malloc() and free()
  16. Lab 16: Student Record Management using Structures (Name, Roll, Marks, Percentage)
  17. Lab 17: Array of Structures Sorting by Student Roll Number
  18. Lab 18: Writing and Reading Formatted Data to a Sequential Text File (fprintf and fscanf)
  19. Lab 19: Copying Contents of One File to Another Character by Character (fgetc and fputc)
  20. Lab 20: Binary Record Storage and Retrieval using fwrite() and fread()

```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 ```