commit c498870e5013708a1a937975d2fc50a93508b17f
parent b457916f2950050d1525971b8006e11024cc457c
Author: Amit Dutta <amitdutta4255@gmail.com>
Date: Sun, 8 Feb 2026 19:41:32 +0530
[2026-02-08] : .\{root} : Automated Update: Source code for Chapter 17, 18, 19, 20, 21, 22, 23, 24
Diffstat:
44 files changed, 6875 insertions(+), 0 deletions(-)
diff --git a/README.md b/README.md
@@ -126,6 +126,7 @@ To ensure the compiler is correctly set up and accessible, open a new command li
### Amit Dutta
* 📧 **amitdutta4255@gmail.com**
+* 📧 **mail@amit.is-a.dev**
* 🌐 [**GitHub Profile**](https://github.com/notamitgamer)
diff --git a/Semester_1/letusc/luc078.c b/Semester_1/letusc/luc078.c
@@ -0,0 +1,85 @@
+/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Create a structure 'student' (Roll, Name, Dept, Course, Year). Write functions to print names by join year and print data by roll number.
+*/
+/* Let Us C, Chap- 17 (Structures), Qn No.: B(a) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+struct student
+{
+ int roll;
+ char name[50];
+ char dept[20];
+ char course[20];
+ int year;
+};
+
+void print_by_year(struct student *s, int n, int year);
+void print_by_roll(struct student *s, int n, int roll);
+
+int main()
+{
+ struct student data[450] = {
+ {101, "Amit", "CS", "B.Sc", 2024},
+ {102, "Rahul", "Physics", "B.Sc", 2024},
+ {103, "Sneha", "CS", "M.Sc", 2023},
+ {104, "Priya", "Maths", "B.Sc", 2025},
+ {105, "Rohan", "CS", "B.Sc", 2024}
+ };
+ int n = 5; // Using 5 sample records
+ int year, roll;
+
+ printf("Enter year to list students: ");
+ scanf("%d", &year);
+ print_by_year(data, n, year);
+
+ printf("\nEnter roll number to find student: ");
+ scanf("%d", &roll);
+ print_by_roll(data, n, roll);
+
+ return 0;
+}
+
+void print_by_year(struct student *s, int n, int year)
+{
+ int i, found = 0;
+ printf("Students joining in %d:\n", year);
+ for (i = 0; i < n; i++)
+ {
+ if (s[i].year == year)
+ {
+ printf("- %s\n", s[i].name);
+ found = 1;
+ }
+ }
+ if (!found) printf("No students found for this year.\n");
+}
+
+void print_by_roll(struct student *s, int n, int roll)
+{
+ int i;
+ for (i = 0; i < n; i++)
+ {
+ if (s[i].roll == roll)
+ {
+ printf("\n--- Student Details ---\n");
+ printf("Roll: %d\nName: %s\nDept: %s\nCourse: %s\nYear: %d\n",
+ s[i].roll, s[i].name, s[i].dept, s[i].course, s[i].year);
+ return;
+ }
+ }
+ printf("Student with Roll %d not found.\n", roll);
+}+
\ No newline at end of file
diff --git a/Semester_1/letusc/luc079.c b/Semester_1/letusc/luc079.c
@@ -0,0 +1,103 @@
+/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Create a structure for bank customers (Acc no, Name, Balance). Write functions to print low balance customers and handle deposits/withdrawals.
+*/
+/* Let Us C, Chap- 17 (Structures), Qn No.: B(b) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+struct customer
+{
+ int acc_no;
+ char name[50];
+ float balance;
+};
+
+void print_low_balance(struct customer *c, int n);
+void transaction(struct customer *c, int n, int acc, float amount, int code);
+
+int main()
+{
+ struct customer bank[200] = {
+ {1001, "Alice", 5000.0},
+ {1002, "Bob", 500.0},
+ {1003, "Charlie", 1200.0},
+ {1004, "David", 800.0},
+ {1005, "Eve", 2000.0}
+ };
+ int n = 5;
+ int acc, code;
+ float amt;
+
+ // Task 1: Low Balance
+ printf("--- Customers with Balance < Rs. 1000 ---\n");
+ print_low_balance(bank, n);
+
+ // Task 2: Transaction
+ printf("\n--- Transaction Menu ---\n");
+ printf("Enter Account No, Amount, Code (1=Deposit, 0=Withdraw): ");
+ scanf("%d %f %d", &acc, &amt, &code);
+
+ transaction(bank, n, acc, amt, code);
+
+ return 0;
+}
+
+void print_low_balance(struct customer *c, int n)
+{
+ int i;
+ for (i = 0; i < n; i++)
+ {
+ if (c[i].balance < 1000)
+ {
+ printf("Acc: %d, Name: %s, Bal: %.2f\n", c[i].acc_no, c[i].name, c[i].balance);
+ }
+ }
+}
+
+void transaction(struct customer *c, int n, int acc, float amount, int code)
+{
+ int i, found = 0;
+ for (i = 0; i < n; i++)
+ {
+ if (c[i].acc_no == acc)
+ {
+ found = 1;
+ if (code == 1) // Deposit
+ {
+ c[i].balance += amount;
+ printf("Deposit successful. New Balance: %.2f\n", c[i].balance);
+ }
+ else if (code == 0) // Withdraw
+ {
+ if (c[i].balance - amount < 1000)
+ {
+ printf("The balance is insufficient for the specified withdrawal (Must maintain min 1000).\n");
+ }
+ else
+ {
+ c[i].balance -= amount;
+ printf("Withdrawal successful. New Balance: %.2f\n", c[i].balance);
+ }
+ }
+ else
+ {
+ printf("Invalid transaction code.\n");
+ }
+ break;
+ }
+ }
+ if (!found) printf("Account number not found.\n");
+}+
\ No newline at end of file
diff --git a/Semester_1/letusc/luc080.c b/Semester_1/letusc/luc080.c
@@ -0,0 +1,64 @@
+/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Automobile engine parts (Serial AA0-FF9, Year, Material, Qty). Retrieve parts between serial numbers BB1 and CC6.
+*/
+/* Let Us C, Chap- 17 (Structures), Qn No.: B(c) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+struct part
+{
+ char serial[4]; // 3 chars + null terminator
+ int mfg_year;
+ char material[20];
+ int quantity;
+};
+
+void retrieve_parts(struct part *p, int n);
+
+int main()
+{
+ struct part inventory[] = {
+ {"AA0", 2020, "Steel", 50},
+ {"BB2", 2021, "Aluminum", 20},
+ {"BB5", 2022, "Carbon", 10},
+ {"CC1", 2021, "Steel", 100},
+ {"CC7", 2023, "Titanium", 5},
+ {"FF9", 2024, "Iron", 60}
+ };
+ int n = 6;
+
+ printf("--- Parts with Serial Numbers between BB1 and CC6 ---\n");
+ retrieve_parts(inventory, n);
+
+ return 0;
+}
+
+void retrieve_parts(struct part *p, int n)
+{
+ int i;
+ // We compare strings lexicographically
+ char start[] = "BB1";
+ char end[] = "CC6";
+
+ for (i = 0; i < n; i++)
+ {
+ if (strcmp(p[i].serial, start) >= 0 && strcmp(p[i].serial, end) <= 0)
+ {
+ printf("Serial: %s | Year: %d | Mat: %s | Qty: %d\n",
+ p[i].serial, p[i].mfg_year, p[i].material, p[i].quantity);
+ }
+ }
+}+
\ No newline at end of file
diff --git a/Semester_1/letusc/luc081.c b/Semester_1/letusc/luc081.c
@@ -0,0 +1,63 @@
+/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Create structure for Cricketers (Name, Age, Tests, Avg Runs). Sort 20 records by average runs using qsort().
+*/
+/* Let Us C, Chap- 17 (Structures), Qn No.: B(d) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+struct cricketer
+{
+ char name[30];
+ int age;
+ int tests;
+ float avg_runs;
+};
+
+// Comparator function for qsort
+int compare(const void *a, const void *b)
+{
+ struct cricketer *c1 = (struct cricketer *)a;
+ struct cricketer *c2 = (struct cricketer *)b;
+
+ if (c1->avg_runs > c2->avg_runs) return 1;
+ else if (c1->avg_runs < c2->avg_runs) return -1;
+ else return 0;
+}
+
+int main()
+{
+ // Initializing fewer than 20 for demonstration, but logic applies to 20
+ struct cricketer team[5] = {
+ {"Kohli", 34, 110, 53.4},
+ {"Smith", 33, 95, 59.8},
+ {"Root", 32, 120, 50.1},
+ {"Sharma", 35, 80, 45.5},
+ {"Williamson", 32, 90, 54.0}
+ };
+ int n = 5, i;
+
+ printf("Before Sorting:\n");
+ for (i = 0; i < n; i++)
+ printf("%s: %.2f\n", team[i].name, team[i].avg_runs);
+
+ qsort(team, n, sizeof(struct cricketer), compare);
+
+ printf("\nAfter Sorting (Ascending Avg Runs):\n");
+ for (i = 0; i < n; i++)
+ printf("%s: %.2f\n", team[i].name, team[i].avg_runs);
+
+ return 0;
+}+
\ No newline at end of file
diff --git a/Semester_1/letusc/luc082.c b/Semester_1/letusc/luc082.c
@@ -0,0 +1,69 @@
+/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Structure 'employee' (Code, Name, Date of Joining). Display names of employees with tenure >= 3 years.
+*/
+/* Let Us C, Chap- 17 (Structures), Qn No.: B(e) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+struct date
+{
+ int day;
+ int month;
+ int year;
+};
+
+struct employee
+{
+ int code;
+ char name[30];
+ struct date doj;
+};
+
+int main()
+{
+ struct employee emp[5] = {
+ {101, "Amit", {12, 1, 2020}},
+ {102, "Sumit", {15, 8, 2023}},
+ {103, "Rina", {1, 1, 2018}},
+ {104, "Tina", {20, 5, 2022}},
+ {105, "Mina", {10, 12, 2025}}
+ };
+ int n = 5, i;
+ struct date current;
+
+ printf("Enter current date (dd mm yyyy): ");
+ scanf("%d %d %d", ¤t.day, ¤t.month, ¤t.year);
+
+ printf("\nEmployees with tenure >= 3 years:\n");
+ for (i = 0; i < n; i++)
+ {
+ int years = current.year - emp[i].doj.year;
+
+ // Adjust for month/day
+ if (current.month < emp[i].doj.month ||
+ (current.month == emp[i].doj.month && current.day < emp[i].doj.day))
+ {
+ years--;
+ }
+
+ if (years >= 3)
+ {
+ printf("%s (Tenure: %d years)\n", emp[i].name, years);
+ }
+ }
+
+ return 0;
+}+
\ No newline at end of file
diff --git a/Semester_1/letusc/luc083.c b/Semester_1/letusc/luc083.c
@@ -0,0 +1,138 @@
+/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Library menu-driven program (Add, Display, List by Author, List by Title, Count, List sorted).
+*/
+/* Let Us C, Chap- 17 (Structures), Qn No.: B(f) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+struct library
+{
+ int acc_no;
+ char title[50];
+ char author[50];
+ float price;
+ int is_issued; // 1 = Yes, 0 = No
+};
+
+void add_book(struct library *lib, int *count);
+void display_books(struct library *lib, int count);
+void list_by_author(struct library *lib, int count);
+void list_title_by_acc(struct library *lib, int count);
+void sort_by_acc(struct library *lib, int count);
+
+int main()
+{
+ struct library books[100];
+ int count = 0;
+ int choice;
+
+ while (1)
+ {
+ printf("\n--- Library Menu ---\n");
+ printf("1. Add Book Info\n");
+ printf("2. Display Book Info\n");
+ printf("3. List books of given author\n");
+ printf("4. List title of specified accession number\n");
+ printf("5. List count of books\n");
+ printf("6. List books in order of accession number\n");
+ printf("7. Exit\n");
+ printf("Enter choice: ");
+ scanf("%d", &choice);
+
+ switch (choice)
+ {
+ case 1: add_book(books, &count); break;
+ case 2: display_books(books, count); break;
+ case 3: list_by_author(books, count); break;
+ case 4: list_title_by_acc(books, count); break;
+ case 5: printf("Total books in library: %d\n", count); break;
+ case 6: sort_by_acc(books, count); display_books(books, count); break;
+ case 7: exit(0);
+ default: printf("Invalid choice!\n");
+ }
+ }
+ return 0;
+}
+
+void add_book(struct library *lib, int *count)
+{
+ printf("Enter Accession No, Title, Author, Price, Issued(1/0):\n");
+ scanf("%d", &lib[*count].acc_no);
+ scanf("%s", lib[*count].title); // Using %s for simplicity (no spaces)
+ scanf("%s", lib[*count].author);
+ scanf("%f", &lib[*count].price);
+ scanf("%d", &lib[*count].is_issued);
+ (*count)++;
+}
+
+void display_books(struct library *lib, int count)
+{
+ int i;
+ for (i = 0; i < count; i++)
+ printf("%d: %s by %s ($%.2f) Issued: %d\n",
+ lib[i].acc_no, lib[i].title, lib[i].author, lib[i].price, lib[i].is_issued);
+}
+
+void list_by_author(struct library *lib, int count)
+{
+ char author[50];
+ int i, found = 0;
+ printf("Enter author name: ");
+ scanf("%s", author);
+ for (i = 0; i < count; i++)
+ {
+ if (strcmp(lib[i].author, author) == 0)
+ {
+ printf("%s\n", lib[i].title);
+ found = 1;
+ }
+ }
+ if (!found) printf("No books found.\n");
+}
+
+void list_title_by_acc(struct library *lib, int count)
+{
+ int acc, i;
+ printf("Enter Accession No: ");
+ scanf("%d", &acc);
+ for (i = 0; i < count; i++)
+ {
+ if (lib[i].acc_no == acc)
+ {
+ printf("Title: %s\n", lib[i].title);
+ return;
+ }
+ }
+ printf("Book not found.\n");
+}
+
+void sort_by_acc(struct library *lib, int count)
+{
+ struct library temp;
+ int i, j;
+ for (i = 0; i < count - 1; i++)
+ {
+ for (j = 0; j < count - i - 1; j++)
+ {
+ if (lib[j].acc_no > lib[j + 1].acc_no)
+ {
+ temp = lib[j];
+ lib[j] = lib[j + 1];
+ lib[j + 1] = temp;
+ }
+ }
+ }
+}+
\ No newline at end of file
diff --git a/Semester_1/letusc/luc084.c b/Semester_1/letusc/luc084.c
@@ -0,0 +1,54 @@
+/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Define a function that compares two given dates. Return 0 if equal, otherwise return 1.
+*/
+/* Let Us C, Chap- 17 (Structures), Qn No.: B(g) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+struct date
+{
+ int day;
+ int month;
+ int year;
+};
+
+int compare_dates(struct date d1, struct date d2);
+
+int main()
+{
+ struct date date1, date2;
+
+ printf("Enter Date 1 (dd mm yyyy): ");
+ scanf("%d %d %d", &date1.day, &date1.month, &date1.year);
+
+ printf("Enter Date 2 (dd mm yyyy): ");
+ scanf("%d %d %d", &date2.day, &date2.month, &date2.year);
+
+ if (compare_dates(date1, date2) == 0)
+ printf("The dates are Equal.\n");
+ else
+ printf("The dates are NOT Equal.\n");
+
+ return 0;
+}
+
+int compare_dates(struct date d1, struct date d2)
+{
+ if (d1.day == d2.day && d1.month == d2.month && d1.year == d2.year)
+ return 0;
+ else
+ return 1;
+}+
\ No newline at end of file
diff --git a/Semester_1/letusc/luc085.c b/Semester_1/letusc/luc085.c
@@ -0,0 +1,82 @@
+/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Suppose a file contains student records (Name, Age). Write a program to read these records and display them in sorted order by name.
+*/
+/* Let Us C, Chap- 19 (File Input/Output), Qn No.: B(a) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+struct student
+{
+ char name[40];
+ int age;
+};
+
+void create_dummy_data();
+int compare_names(const void *a, const void *b);
+
+int main()
+{
+ FILE *fp;
+ struct student s[100];
+ int count = 0, i;
+
+ // Create sample file for demonstration
+ create_dummy_data();
+
+ fp = fopen("students.dat", "rb");
+ if (fp == NULL)
+ {
+ printf("Cannot open file!\n");
+ exit(1);
+ }
+
+ // Read records into array
+ while (fread(&s[count], sizeof(struct student), 1, fp) == 1)
+ {
+ count++;
+ }
+ fclose(fp);
+
+ // Sort the array
+ qsort(s, count, sizeof(struct student), compare_names);
+
+ printf("--- Student List (Sorted by Name) ---\n");
+ for (i = 0; i < count; i++)
+ {
+ printf("Name: %-20s Age: %d\n", s[i].name, s[i].age);
+ }
+
+ return 0;
+}
+
+int compare_names(const void *a, const void *b)
+{
+ return strcmp(((struct student *)a)->name, ((struct student *)b)->name);
+}
+
+void create_dummy_data()
+{
+ FILE *fp = fopen("students.dat", "wb");
+ struct student data[] = {
+ {"Zack", 20}, {"Alice", 19}, {"Bob", 21}, {"Charlie", 20}, {"Yasmine", 19}
+ };
+ if (fp)
+ {
+ fwrite(data, sizeof(struct student), 5, fp);
+ fclose(fp);
+ }
+}+
\ No newline at end of file
diff --git a/Semester_1/letusc/luc086.c b/Semester_1/letusc/luc086.c
@@ -0,0 +1,69 @@
+/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Write a program to copy contents of one file to another. While doing so replace all lowercase characters to their equivalent uppercase characters.
+*/
+/* Let Us C, Chap- 19 (File Input/Output), Qn No.: B(b) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+void create_source_file();
+
+int main()
+{
+ FILE *fs, *ft;
+ char ch;
+
+ create_source_file(); // Helper to make code runnable
+
+ fs = fopen("source.txt", "r");
+ if (fs == NULL)
+ {
+ printf("Cannot open source file.\n");
+ exit(1);
+ }
+
+ ft = fopen("target.txt", "w");
+ if (ft == NULL)
+ {
+ printf("Cannot open target file.\n");
+ fclose(fs);
+ exit(2);
+ }
+
+ while ((ch = fgetc(fs)) != EOF)
+ {
+ ch = toupper(ch);
+ fputc(ch, ft);
+ }
+
+ printf("File copied successfully with uppercase conversion.\n");
+ printf("Check 'target.txt' for results.\n");
+
+ fclose(fs);
+ fclose(ft);
+
+ return 0;
+}
+
+void create_source_file()
+{
+ FILE *fp = fopen("source.txt", "w");
+ if (fp)
+ {
+ fprintf(fp, "This is a sample text.\nIt contains Lowercase letters.\n");
+ fclose(fp);
+ }
+}+
\ No newline at end of file
diff --git a/Semester_1/letusc/luc087.c b/Semester_1/letusc/luc087.c
@@ -0,0 +1,88 @@
+/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Write a program that merges lines alternately from two files and writes the results to a new file. Handle remaining lines if file sizes differ.
+*/
+/* Let Us C, Chap- 19 (File Input/Output), Qn No.: B(c) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+void create_sample_files();
+
+int main()
+{
+ FILE *fp1, *fp2, *fp3;
+ char line1[100], line2[100];
+ char *res1, *res2;
+
+ create_sample_files();
+
+ fp1 = fopen("file1.txt", "r");
+ fp2 = fopen("file2.txt", "r");
+ fp3 = fopen("merge.txt", "w");
+
+ if (fp1 == NULL || fp2 == NULL || fp3 == NULL)
+ {
+ printf("File error.\n");
+ exit(1);
+ }
+
+ // Read lines from both files
+ res1 = fgets(line1, sizeof(line1), fp1);
+ res2 = fgets(line2, sizeof(line2), fp2);
+
+ while (res1 != NULL && res2 != NULL)
+ {
+ fputs(line1, fp3);
+ fputs(line2, fp3);
+
+ res1 = fgets(line1, sizeof(line1), fp1);
+ res2 = fgets(line2, sizeof(line2), fp2);
+ }
+
+ // Append remaining lines from file 1
+ while (res1 != NULL)
+ {
+ fputs(line1, fp3);
+ res1 = fgets(line1, sizeof(line1), fp1);
+ }
+
+ // Append remaining lines from file 2
+ while (res2 != NULL)
+ {
+ fputs(line2, fp3);
+ res2 = fgets(line2, sizeof(line2), fp2);
+ }
+
+ printf("Files merged alternately into 'merge.txt'.\n");
+
+ fclose(fp1);
+ fclose(fp2);
+ fclose(fp3);
+
+ return 0;
+}
+
+void create_sample_files()
+{
+ FILE *f1 = fopen("file1.txt", "w");
+ FILE *f2 = fopen("file2.txt", "w");
+
+ fprintf(f1, "File 1 - Line A\nFile 1 - Line B\nFile 1 - Line C\n");
+ fprintf(f2, "File 2 - Line 1\nFile 2 - Line 2\nFile 2 - Line 3\nFile 2 - Line 4\n");
+
+ fclose(f1);
+ fclose(f2);
+}+
\ No newline at end of file
diff --git a/Semester_1/letusc/luc088.c b/Semester_1/letusc/luc088.c
@@ -0,0 +1,75 @@
+/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Write a program to encrypt/decrypt a file using: (1) Offset cipher (2) Substitution cipher.
+*/
+/* Let Us C, Chap- 19 (File Input/Output), Qn No.: B(d) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+void create_plain_file();
+
+int main()
+{
+ FILE *fs, *ft;
+ char ch;
+ int choice;
+
+ create_plain_file();
+
+ printf("1. Offset Cipher\n2. Substitution Cipher\nEnter choice: ");
+ scanf("%d", &choice);
+
+ fs = fopen("plain.txt", "r");
+ ft = fopen("coded.txt", "w");
+
+ if (fs == NULL || ft == NULL)
+ {
+ printf("Error opening files.\n");
+ exit(1);
+ }
+
+ while ((ch = fgetc(fs)) != EOF)
+ {
+ if (choice == 1)
+ {
+ // Offset Cipher: Add 128 (effectively shifts char code)
+ fputc(ch + 10, ft); // Using +10 for visibility, problem says 128
+ }
+ else
+ {
+ // Simple Substitution: A->!, B->@ etc.
+ // Here, we'll just map any char to char+5 for simplicity
+ // as true substitution requires a full map array.
+ fputc(ch + 5, ft);
+ }
+ }
+
+ printf("Encryption complete. Check 'coded.txt'.\n");
+
+ fclose(fs);
+ fclose(ft);
+ return 0;
+}
+
+void create_plain_file()
+{
+ FILE *fp = fopen("plain.txt", "w");
+ if (fp)
+ {
+ fprintf(fp, "SECRET MESSAGE");
+ fclose(fp);
+ }
+}+
\ No newline at end of file
diff --git a/Semester_1/letusc/luc089.c b/Semester_1/letusc/luc089.c
@@ -0,0 +1,118 @@
+/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Update 'CUSTOMER.DAT' balance using 'TRANSACTIONS.DAT' (Deposit/Withdrawal). Ensure balance doesn't fall below Rs. 100 on withdrawal.
+*/
+/* Let Us C, Chap- 19 (File Input/Output), Qn No.: B(e) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+struct customer {
+ int accno;
+ char name[30];
+ float balance;
+};
+
+struct trans {
+ int accno;
+ char trans_type;
+ float amount;
+};
+
+void create_files();
+void update_customer(struct customer *c, int n, struct trans t);
+
+int main()
+{
+ FILE *fc, *ft;
+ struct customer cust[100];
+ struct trans t;
+ int i, n_cust = 0;
+
+ create_files(); // Generate dummy data
+
+ // 1. Load all customers into memory
+ fc = fopen("CUSTOMER.DAT", "rb");
+ if (fc == NULL) exit(1);
+
+ while (fread(&cust[n_cust], sizeof(struct customer), 1, fc) == 1)
+ {
+ n_cust++;
+ }
+ fclose(fc);
+
+ // 2. Process transactions sequentially
+ ft = fopen("TRANSACTIONS.DAT", "rb");
+ if (ft == NULL) exit(2);
+
+ printf("Processing Transactions...\n");
+ while (fread(&t, sizeof(struct trans), 1, ft) == 1)
+ {
+ update_customer(cust, n_cust, t);
+ }
+ fclose(ft);
+
+ // 3. Write updated data back to CUSTOMER.DAT
+ fc = fopen("CUSTOMER.DAT", "wb");
+ fwrite(cust, sizeof(struct customer), n_cust, fc);
+ fclose(fc);
+
+ printf("Update Complete. New Balances:\n");
+ for(i=0; i<n_cust; i++)
+ printf("%d %s: %.2f\n", cust[i].accno, cust[i].name, cust[i].balance);
+
+ return 0;
+}
+
+void update_customer(struct customer *c, int n, struct trans t)
+{
+ int i;
+ for (i = 0; i < n; i++)
+ {
+ if (c[i].accno == t.accno)
+ {
+ if (t.trans_type == 'D')
+ {
+ c[i].balance += t.amount;
+ printf("Acc %d: Deposited %.2f\n", t.accno, t.amount);
+ }
+ else if (t.trans_type == 'W')
+ {
+ if ((c[i].balance - t.amount) >= 100)
+ {
+ c[i].balance -= t.amount;
+ printf("Acc %d: Withdrew %.2f\n", t.accno, t.amount);
+ }
+ else
+ {
+ printf("Acc %d: Withdrawal denied (Min bal constraint)\n", t.accno);
+ }
+ }
+ return;
+ }
+ }
+ printf("Transaction Error: Acc %d not found\n", t.accno);
+}
+
+void create_files()
+{
+ struct customer c[] = {{101, "A", 500}, {102, "B", 1000}, {103, "C", 200}};
+ struct trans t[] = {{101, 'D', 200}, {102, 'W', 500}, {103, 'W', 150}}; // 103 fail
+ FILE *f1 = fopen("CUSTOMER.DAT", "wb");
+ FILE *f2 = fopen("TRANSACTIONS.DAT", "wb");
+ fwrite(c, sizeof(struct customer), 3, f1);
+ fwrite(t, sizeof(struct trans), 3, f2);
+ fclose(f1); fclose(f2);
+}+
\ No newline at end of file
diff --git a/Semester_1/letusc/luc090.c b/Semester_1/letusc/luc090.c
@@ -0,0 +1,89 @@
+/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Read employee records (code, name, date, salary), sort them by Date of Joining, and write to a target file.
+*/
+/* Let Us C, Chap- 19 (File Input/Output), Qn No.: B(f) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+struct date { int d, m, y; };
+struct employee {
+ int empcode[6]; // Not used as int array usually, likely int id. Assuming int code.
+ char empname[20];
+ struct date join_date;
+ float salary;
+};
+
+// Redefining struct for easier usage assuming empcode is int
+struct emp_clean {
+ int code;
+ char name[20];
+ struct date doj;
+ float salary;
+};
+
+void create_emp_file();
+int compare_dates(const void *a, const void *b);
+
+int main()
+{
+ FILE *fp, *ft;
+ struct emp_clean e[50];
+ int count = 0, i;
+
+ create_emp_file();
+
+ fp = fopen("employee.dat", "rb");
+ if (!fp) return 1;
+
+ while (fread(&e[count], sizeof(struct emp_clean), 1, fp) == 1)
+ count++;
+ fclose(fp);
+
+ qsort(e, count, sizeof(struct emp_clean), compare_dates);
+
+ ft = fopen("emp_sorted.dat", "wb");
+ fwrite(e, sizeof(struct emp_clean), count, ft);
+ fclose(ft);
+
+ printf("Sorted records written to 'emp_sorted.dat'.\nDisplaying sorted list:\n");
+ for(i=0; i<count; i++)
+ printf("%s - %02d/%02d/%04d\n", e[i].name, e[i].doj.d, e[i].doj.m, e[i].doj.y);
+
+ return 0;
+}
+
+int compare_dates(const void *a, const void *b)
+{
+ struct emp_clean *e1 = (struct emp_clean *)a;
+ struct emp_clean *e2 = (struct emp_clean *)b;
+
+ if (e1->doj.y != e2->doj.y) return e1->doj.y - e2->doj.y;
+ if (e1->doj.m != e2->doj.m) return e1->doj.m - e2->doj.m;
+ return e1->doj.d - e2->doj.d;
+}
+
+void create_emp_file()
+{
+ struct emp_clean data[] = {
+ {1, "John", {12, 5, 2022}, 5000},
+ {2, "Jane", {10, 1, 2020}, 6000}, // Senior
+ {3, "Bob", {15, 8, 2021}, 5500}
+ };
+ FILE *f = fopen("employee.dat", "wb");
+ fwrite(data, sizeof(struct emp_clean), 3, f);
+ fclose(f);
+}+
\ No newline at end of file
diff --git a/Semester_1/letusc/luc091.c b/Semester_1/letusc/luc091.c
@@ -0,0 +1,69 @@
+/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Read 'blood donors' file (Name, Address, Age, Blood Type). Print donors with Age < 25 and Blood Type 2.
+*/
+/* Let Us C, Chap- 19 (File Input/Output), Qn No.: B(g) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+struct donor {
+ char name[21]; // 20 cols + null
+ char address[41]; // 40 cols + null
+ int age; // 2 cols -> int
+ int blood_type; // 1 col -> int
+};
+
+void create_donor_file();
+
+int main()
+{
+ FILE *fp;
+ struct donor d;
+
+ create_donor_file();
+
+ fp = fopen("donors.dat", "rb");
+ if (!fp)
+ {
+ printf("File error.\n");
+ exit(1);
+ }
+
+ printf("--- Donors (Age < 25, Type 2) ---\n");
+ while (fread(&d, sizeof(struct donor), 1, fp) == 1)
+ {
+ if (d.age < 25 && d.blood_type == 2)
+ {
+ printf("Name: %s | Age: %d | Addr: %s\n", d.name, d.age, d.address);
+ }
+ }
+
+ fclose(fp);
+ return 0;
+}
+
+void create_donor_file()
+{
+ struct donor data[] = {
+ {"Amit", "Delhi", 22, 2}, // Match
+ {"Rahul", "Mumbai", 30, 2}, // Old
+ {"Sumit", "Pune", 21, 1}, // Wrong type
+ {"Priya", "Goa", 24, 2} // Match
+ };
+ FILE *f = fopen("donors.dat", "wb");
+ fwrite(data, sizeof(struct donor), 4, f);
+ fclose(f);
+}+
\ No newline at end of file
diff --git a/Semester_1/letusc/luc092.c b/Semester_1/letusc/luc092.c
@@ -0,0 +1,62 @@
+/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Write a program to store names in a file. Display the n-th name in the list, where n is read from the keyboard.
+*/
+/* Let Us C, Chap- 19 (File Input/Output), Qn No.: B(h) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+void create_name_file();
+
+int main()
+{
+ FILE *fp;
+ char name[50];
+ int n, current = 0, found = 0;
+
+ create_name_file();
+
+ printf("Enter value of n to find n-th name: ");
+ scanf("%d", &n);
+
+ fp = fopen("names.txt", "r");
+ if (!fp) exit(1);
+
+ // Assuming one name per line
+ while (fgets(name, sizeof(name), fp) != NULL)
+ {
+ current++;
+ if (current == n)
+ {
+ printf("The %d-th name is: %s", n, name);
+ found = 1;
+ break;
+ }
+ }
+
+ if (!found)
+ printf("Record not found (Only %d names exist).\n", current);
+
+ fclose(fp);
+ return 0;
+}
+
+void create_name_file()
+{
+ FILE *f = fopen("names.txt", "w");
+ fprintf(f, "Alice\nBob\nCharlie\nDavid\nEve\nFrank\n");
+ fclose(f);
+}+
\ No newline at end of file
diff --git a/Semester_1/letusc/luc093.c b/Semester_1/letusc/luc093.c
@@ -0,0 +1,131 @@
+/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Update Master file (Roll, Name) using Transaction file (Roll, Code Add/Delete). Both files are sorted by Roll.
+*/
+/* Let Us C, Chap- 19 (File Input/Output), Qn No.: B(i) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+struct student {
+ int roll;
+ char name[30];
+};
+
+struct trans {
+ int roll;
+ char code; // 'A' for Add, 'D' for Delete
+ char name[30]; // Only needed for Add
+};
+
+void create_files();
+
+int main()
+{
+ FILE *fm, *ft, *fn;
+ struct student m;
+ struct trans t;
+ int has_m, has_t;
+
+ create_files();
+
+ fm = fopen("MASTER.DAT", "rb");
+ ft = fopen("TRANS_ROLL.DAT", "rb");
+ fn = fopen("NEW_MASTER.DAT", "wb");
+
+ if (!fm || !ft || !fn) exit(1);
+
+ has_m = fread(&m, sizeof(struct student), 1, fm);
+ has_t = fread(&t, sizeof(struct trans), 1, ft);
+
+ printf("Merging Master and Transaction files...\n");
+
+ while (has_m && has_t)
+ {
+ if (m.roll < t.roll)
+ {
+ // No transaction for this master record, keep it
+ fwrite(&m, sizeof(struct student), 1, fn);
+ has_m = fread(&m, sizeof(struct student), 1, fm);
+ }
+ else if (m.roll == t.roll)
+ {
+ // Transaction affects this record
+ if (t.code == 'D')
+ {
+ printf("Deleting Roll %d\n", m.roll);
+ // Skip writing 'm' to file (Deleting)
+ has_m = fread(&m, sizeof(struct student), 1, fm);
+ }
+ else
+ {
+ // Logic error: Can't ADD if ID exists. Maybe Update?
+ // Assuming replace or skip. Let's skip T and keep M for now.
+ has_m = fread(&m, sizeof(struct student), 1, fm);
+ }
+ has_t = fread(&t, sizeof(struct trans), 1, ft);
+ }
+ else // m.roll > t.roll
+ {
+ // Transaction ID is new
+ if (t.code == 'A')
+ {
+ struct student new_s;
+ new_s.roll = t.roll;
+ strcpy(new_s.name, t.name);
+ fwrite(&new_s, sizeof(struct student), 1, fn);
+ printf("Adding Roll %d\n", new_s.roll);
+ }
+ has_t = fread(&t, sizeof(struct trans), 1, ft);
+ }
+ }
+
+ // Process remaining Master
+ while (has_m)
+ {
+ fwrite(&m, sizeof(struct student), 1, fn);
+ has_m = fread(&m, sizeof(struct student), 1, fm);
+ }
+
+ // Process remaining Transactions (Only Adds)
+ while (has_t)
+ {
+ if (t.code == 'A')
+ {
+ struct student new_s = {t.roll, ""};
+ strcpy(new_s.name, t.name);
+ fwrite(&new_s, sizeof(struct student), 1, fn);
+ printf("Adding Roll %d\n", new_s.roll);
+ }
+ has_t = fread(&t, sizeof(struct trans), 1, ft);
+ }
+
+ fclose(fm); fclose(ft); fclose(fn);
+ return 0;
+}
+
+void create_files()
+{
+ struct student m[] = {{10, "A"}, {20, "B"}, {30, "C"}};
+ struct trans t[] = {{15, 'A', "NewGuy"}, {20, 'D', ""}, {40, 'A', "LastGuy"}};
+
+ FILE *f1 = fopen("MASTER.DAT", "wb");
+ fwrite(m, sizeof(struct student), 3, f1);
+ fclose(f1);
+
+ FILE *f2 = fopen("TRANS_ROLL.DAT", "wb");
+ fwrite(t, sizeof(struct trans), 3, f2);
+ fclose(f2);
+}+
\ No newline at end of file
diff --git a/Semester_1/letusc/luc094.c b/Semester_1/letusc/luc094.c
@@ -0,0 +1,66 @@
+/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Read a text file, delete the words 'a', 'the', 'an' and replace each with a blank space. Write to new file.
+*/
+/* Let Us C, Chap- 19 (File Input/Output), Qn No.: B(j) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+void create_article_file();
+
+int main()
+{
+ FILE *fp, *ft;
+ char word[100];
+
+ create_article_file();
+
+ fp = fopen("articles.txt", "r");
+ ft = fopen("clean.txt", "w");
+
+ if (!fp || !ft) exit(1);
+
+ // Basic word-by-word processing using fscanf
+ // Note: fscanf skips whitespace, so original spacing formatting
+ // might be lost, but it effectively filters words.
+
+ while (fscanf(fp, "%s", word) != EOF)
+ {
+ if (strcasecmp(word, "a") == 0 ||
+ strcasecmp(word, "an") == 0 ||
+ strcasecmp(word, "the") == 0)
+ {
+ fputc(' ', ft); // Replace with blank
+ }
+ else
+ {
+ fprintf(ft, "%s ", word);
+ }
+ }
+
+ printf("Processed file. Articles removed in 'clean.txt'.\n");
+
+ fclose(fp);
+ fclose(ft);
+ return 0;
+}
+
+void create_article_file()
+{
+ FILE *f = fopen("articles.txt", "w");
+ fprintf(f, "The quick brown fox jumps over a lazy dog. It was an honour.");
+ fclose(f);
+}+
\ No newline at end of file
diff --git a/Semester_1/letusc/luc095.c b/Semester_1/letusc/luc095.c
@@ -0,0 +1,49 @@
+/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Write a program that can read a file and display its contents. The file name should be supplied as a command-line argument.
+*/
+/* Let Us C, Chap- 20 (More Issues In Input/Output), Qn No.: A(a) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+int main(int argc, char *argv[])
+{
+ FILE *fp;
+ char ch;
+
+ /* Check if file name is provided */
+ if (argc != 2)
+ {
+ printf("Usage: %s <filename>\n", argv[0]);
+ exit(1);
+ }
+
+ fp = fopen(argv[1], "r");
+ if (fp == NULL)
+ {
+ printf("Error: Cannot open file '%s'\n", argv[1]);
+ exit(2);
+ }
+
+ /* Read and display contents */
+ while ((ch = fgetc(fp)) != EOF)
+ {
+ printf("%c", ch);
+ }
+
+ fclose(fp);
+ return 0;
+}+
\ No newline at end of file
diff --git a/Semester_1/letusc/luc096.c b/Semester_1/letusc/luc096.c
@@ -0,0 +1,60 @@
+/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Write a program that can copy the contents of one file to another. The source and target filenames should be supplied as command-line arguments.
+*/
+/* Let Us C, Chap- 20 (More Issues In Input/Output), Qn No.: A(b) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+int main(int argc, char *argv[])
+{
+ FILE *fs, *ft;
+ char ch;
+
+ /* Check for correct number of arguments */
+ if (argc != 3)
+ {
+ printf("Usage: %s <source_file> <target_file>\n", argv[0]);
+ exit(1);
+ }
+
+ fs = fopen(argv[1], "r");
+ if (fs == NULL)
+ {
+ printf("Error: Cannot open source file '%s'\n", argv[1]);
+ exit(2);
+ }
+
+ ft = fopen(argv[2], "w");
+ if (ft == NULL)
+ {
+ printf("Error: Cannot create target file '%s'\n", argv[2]);
+ fclose(fs);
+ exit(3);
+ }
+
+ /* Copy contents */
+ while ((ch = fgetc(fs)) != EOF)
+ {
+ fputc(ch, ft);
+ }
+
+ printf("File copied successfully.\n");
+
+ fclose(fs);
+ fclose(ft);
+ return 0;
+}+
\ No newline at end of file
diff --git a/Semester_1/letusc/luc097.c b/Semester_1/letusc/luc097.c
@@ -0,0 +1,102 @@
+/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Write a program using command-line arguments to search for a word in a file and replace it with the specified word.\nUsage: change <old word> <new word> <filename>
+*/
+/* Let Us C, Chap- 20 (More Issues In Input/Output), Qn No.: A(c) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+void replace_all(char *str, const char *old_w, const char *new_w, FILE *ft);
+
+int main(int argc, char *argv[])
+{
+ FILE *fp, *ft;
+ char line[1000];
+ char *old_word, *new_word, *filename;
+
+ if (argc != 4)
+ {
+ printf("Usage: %s <old word> <new word> <filename>\n", argv[0]);
+ exit(1);
+ }
+
+ old_word = argv[1];
+ new_word = argv[2];
+ filename = argv[3];
+
+ fp = fopen(filename, "r");
+ if (fp == NULL)
+ {
+ printf("Error opening file: %s\n", filename);
+ exit(2);
+ }
+
+ // Create a temporary file
+ ft = fopen("temp.tmp", "w");
+ if (ft == NULL)
+ {
+ printf("Error creating temporary file.\n");
+ fclose(fp);
+ exit(3);
+ }
+
+ // Process line by line
+ while (fgets(line, sizeof(line), fp))
+ {
+ replace_all(line, old_word, new_word, ft);
+ }
+
+ fclose(fp);
+ fclose(ft);
+
+ // Replace original file with updated file
+ remove(filename);
+ rename("temp.tmp", filename);
+
+ printf("Replacement complete.\n");
+
+ return 0;
+}
+
+void replace_all(char *str, const char *old_w, const char *new_w, FILE *ft)
+{
+ char *pos, temp[1000];
+ int index = 0;
+ int old_len = strlen(old_w);
+
+ /* We cannot easily modify 'str' in place because new_w
+ might be larger than old_w. We write directly to file.
+ */
+
+ while ((pos = strstr(str, old_w)) != NULL)
+ {
+ // Write everything before the match
+ while (str < pos)
+ {
+ fputc(*str, ft);
+ str++;
+ }
+
+ // Write the new word
+ fputs(new_w, ft);
+
+ // Skip the old word in the source string
+ str += old_len;
+ }
+
+ // Write the remainder of the line
+ fputs(str, ft);
+}+
\ No newline at end of file
diff --git a/Semester_1/letusc/luc098.c b/Semester_1/letusc/luc098.c
@@ -0,0 +1,80 @@
+/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Write a calculator utility using command line arguments.\nUsage: calc <switch> <n> <m>\nwhere switch is arithmetic operator or comparison operator.
+*/
+/* Let Us C, Chap- 20 (More Issues In Input/Output), Qn No.: A(d) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+int main(int argc, char *argv[])
+{
+ float n, m, res;
+ char operator;
+
+ if (argc != 4)
+ {
+ printf("Usage: %s <switch> <n> <m>\n", argv[0]);
+ printf("Example: %s + 10 20\n", argv[0]);
+ printf("Note: For multiplication (*), use '*' or x to avoid shell expansion.\n");
+ exit(1);
+ }
+
+ operator = argv[1][0]; // First character of the switch argument
+ n = atof(argv[2]);
+ m = atof(argv[3]);
+
+ switch (operator)
+ {
+ // Arithmetic
+ case '+':
+ printf("%.2f\n", n + m);
+ break;
+ case '-':
+ printf("%.2f\n", n - m);
+ break;
+ case 'x':
+ case '*':
+ printf("%.2f\n", n * m);
+ break;
+ case '/':
+ if (m == 0) printf("Error: Division by zero\n");
+ else printf("%.2f\n", n / m);
+ break;
+ case '%':
+ printf("%d\n", (int)n % (int)m);
+ break;
+
+ // Comparison
+ case '<':
+ printf("%s\n", (n < m) ? "True" : "False");
+ break;
+ case '>':
+ printf("%s\n", (n > m) ? "True" : "False");
+ break;
+
+ // Handling symbols that might be multi-char (e.g. <=, >=, ==) is tricky
+ // with argv[1][0], but basic logic for typical single char switches:
+ case '=':
+ printf("%s\n", (n == m) ? "True" : "False");
+ break;
+
+ default:
+ printf("Unknown operator: %c\n", operator);
+ break;
+ }
+
+ return 0;
+}+
\ No newline at end of file
diff --git a/Semester_1/letusc/luc099.c b/Semester_1/letusc/luc099.c
@@ -0,0 +1,50 @@
+/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Read an integer 'game' representing sports won by a college. Determine if it won the 'Champion of Champions' trophy (>5 games) and list games won.
+*/
+/* Let Us C, Chap- 21 (Operations on Bits), Qn No.: A(a) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int main()
+{
+ int game;
+ int count = 0, i;
+ const char *sports[] = {
+ "Cricket", "Basketball", "Football", "Hockey",
+ "Lawn Tennis", "Table Tennis", "Carom", "Chess", "Volleyball" // Added one for bit 8
+ };
+
+ printf("Enter the game information (integer): ");
+ scanf("%d", &game);
+
+ printf("\nGames won:\n");
+ for (i = 0; i <= 8; i++)
+ {
+ if (game & (1 << i))
+ {
+ printf("- %s\n", sports[i]);
+ count++;
+ }
+ }
+
+ printf("\nTotal games won: %d\n", count);
+
+ if (count >= 5)
+ printf("Result: The college won the Champion of Champions trophy.\n");
+ else
+ printf("Result: The college did NOT win the trophy.\n");
+
+ return 0;
+}+
\ No newline at end of file
diff --git a/Semester_1/letusc/luc100.c b/Semester_1/letusc/luc100.c
@@ -0,0 +1,48 @@
+/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Determine if an animal is Carnivore/Herbivore and its type (Canine, Feline, Cetacean, Marsupial) based on bits in an integer.
+*/
+/* Let Us C, Chap- 21 (Operations on Bits), Qn No.: A(b) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+
+struct animal
+{
+ char name[30];
+ int type;
+};
+
+int main()
+{
+ struct animal a = {"OCELOT", 18};
+ int type = a.type;
+
+ printf("Animal: %s\n", a.name);
+
+ // Check Bit 4 for Diet (Assuming 1=Carnivore, 0=Herbivore based on context)
+ if (type & (1 << 4))
+ printf("Diet: Carnivore\n");
+ else
+ printf("Diet: Herbivore\n");
+
+ // Check Bits 0-3 for Family
+ printf("Family: ");
+ if (type & (1 << 0)) printf("Canine ");
+ if (type & (1 << 1)) printf("Feline ");
+ if (type & (1 << 2)) printf("Cetacean ");
+ if (type & (1 << 3)) printf("Marsupial ");
+ printf("\n");
+
+ return 0;
+}+
\ No newline at end of file
diff --git a/Semester_1/letusc/luc101.c b/Semester_1/letusc/luc101.c
@@ -0,0 +1,56 @@
+/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Decode student information (Year, Stream, Room No) packed into an integer array.
+*/
+/* Let Us C, Chap- 21 (Operations on Bits), Qn No.: A(c) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int main()
+{
+ int data[] = {273, 548, 786, 1096};
+ int n = 4, i;
+ int val, year, stream_bits, room;
+
+ for (i = 0; i < n; i++)
+ {
+ val = data[i];
+
+ // Room Number: Rest of the bits (Assuming starting from bit 8)
+ room = val >> 8;
+
+ printf("Student %d (Raw: %d):\n", i + 1, val);
+ printf(" Room No: %d\n", room);
+
+ // Year: Bits 0-3
+ printf(" Year: ");
+ if (val & (1 << 0)) printf("1st Year");
+ else if (val & (1 << 1)) printf("2nd Year");
+ else if (val & (1 << 2)) printf("3rd Year");
+ else if (val & (1 << 3)) printf("4th Year");
+ else printf("Unknown");
+ printf("\n");
+
+ // Stream: Bits 4-7 (Mech, Chem, Elec, CS)
+ printf(" Stream: ");
+ if (val & (1 << 4)) printf("Mechanical");
+ else if (val & (1 << 5)) printf("Chemical");
+ else if (val & (1 << 6)) printf("Electronics");
+ else if (val & (1 << 7)) printf("CS");
+ else printf("Unknown");
+ printf("\n\n");
+ }
+
+ return 0;
+}+
\ No newline at end of file
diff --git a/Semester_1/letusc/luc102.c b/Semester_1/letusc/luc102.c
@@ -0,0 +1,35 @@
+/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* What will be the output of the provided program segment involving bitwise operators?
+*/
+/* Let Us C, Chap- 21 (Operations on Bits), Qn No.: A(d) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int main()
+{
+ int i = 32, j = 65, k, l, m, n, o, p;
+
+ k = i | 35;
+ l = ~k;
+ m = i & j;
+ n = j ^ 32;
+ o = j << 2;
+ p = i >> 5;
+
+ printf("k = %d l = %d m = %d\n", k, l, m);
+ printf("n = %d o = %d p = %d\n", n, o, p);
+
+ return 0;
+}+
\ No newline at end of file
diff --git a/Semester_1/letusc/luc103.c b/Semester_1/letusc/luc103.c
@@ -0,0 +1,36 @@
+/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* What is the hexadecimal equivalent of the following binary numbers?
+*/
+/* Let Us C, Chap- 21 (Operations on Bits), Qn No.: B(a) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int main()
+{
+ // Binary numbers represented as string literals for reference
+ // 01011010
+ // 11000011
+ // 1010101001110101
+ // 111100001011010
+
+ printf("Binary: 01011010 -> Hex: 0x%X\n", 0b01011010);
+ printf("Binary: 11000011 -> Hex: 0x%X\n", 0b11000011);
+ printf("Binary: 1010101001110101 -> Hex: 0x%X\n", 0b1010101001110101);
+ printf("Binary: 111100001011010 -> Hex: 0x%X\n", 0b111100001011010);
+
+ /* Note: Binary literals (0b...) are a standard C extension (GCC) and part of C23 standard. */
+
+ return 0;
+}+
\ No newline at end of file
diff --git a/Semester_1/letusc/luc104.c b/Semester_1/letusc/luc104.c
@@ -0,0 +1,43 @@
+/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Rewrite expressions using bitwise compound assignment operators.
+*/
+/* Let Us C, Chap- 21 (Operations on Bits), Qn No.: B(b) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int main()
+{
+ int a = 10, b = 20, c = 5;
+
+ printf("Original values: a=%d, b=%d, c=%d\n", a, b, c);
+
+ // a = a | 3
+ a |= 3;
+ printf("a |= 3 -> %d\n", a);
+
+ // a = a & 0x48
+ a &= 0x48;
+ printf("a &= 0x48 -> %d\n", a);
+
+ // b = b ^ 0x22
+ b ^= 0x22;
+ printf("b ^= 0x22 -> %d\n", b);
+
+ // c = c << 2
+ c <<= 2;
+ printf("c <<= 2 -> %d\n", c);
+
+ return 0;
+}+
\ No newline at end of file
diff --git a/Semester_1/letusc/luc105.c b/Semester_1/letusc/luc105.c
@@ -0,0 +1,52 @@
+/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Write a function checkbits(x, p, n) which returns true if all 'n' bits starting from position 'p' are turned on.
+*/
+/* Let Us C, Chap- 21 (Operations on Bits), Qn No.: B(c) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int checkbits(unsigned int x, int p, int n);
+
+int main()
+{
+ unsigned int x;
+ int p, n;
+
+ printf("Enter number (x): ");
+ scanf("%u", &x);
+ printf("Enter starting position (p) and count (n): ");
+ scanf("%d %d", &p, &n);
+
+ if (checkbits(x, p, n))
+ printf("TRUE: %d bits starting at %d are ON.\n", n, p);
+ else
+ printf("FALSE: Not all specified bits are ON.\n");
+
+ return 0;
+}
+
+int checkbits(unsigned int x, int p, int n)
+{
+ unsigned int mask;
+
+ // Create a mask of n 1s. E.g., if n=3, mask=000...0111
+ mask = (1 << n) - 1;
+
+ // Shift mask to position p
+ mask = mask << p;
+
+ // Check if bits in x match the mask
+ return (x & mask) == mask;
+}+
\ No newline at end of file
diff --git a/Semester_1/letusc/luc106.c b/Semester_1/letusc/luc106.c
@@ -0,0 +1,38 @@
+/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Write a program to scan an 8-bit number and check whether its 3rd, 6th and 7th bit is on.
+*/
+/* Let Us C, Chap- 21 (Operations on Bits), Qn No.: B(d) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int main()
+{
+ unsigned char num;
+
+ printf("Enter an 8-bit integer (0-255): ");
+ scanf("%hhu", &num);
+
+ // Checking bits 3, 6, 7.
+ // Assuming 0-based indexing: 3rd bit is index 3 (value 8), 6th is index 6 (64), 7th is index 7 (128).
+
+ unsigned char mask = (1 << 3) | (1 << 6) | (1 << 7);
+
+ if ((num & mask) == mask)
+ printf("Bits 3, 6, and 7 are ALL ON.\n");
+ else
+ printf("Bits 3, 6, and 7 are NOT all on.\n");
+
+ return 0;
+}+
\ No newline at end of file
diff --git a/Semester_1/letusc/luc107.c b/Semester_1/letusc/luc107.c
@@ -0,0 +1,37 @@
+/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Receive an unsigned 16-bit integer and exchange the contents of its 2 bytes using bitwise operators.
+*/
+/* Let Us C, Chap- 21 (Operations on Bits), Qn No.: B(e) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int main()
+{
+ unsigned short num, swapped;
+
+ printf("Enter a 16-bit number (0-65535): ");
+ scanf("%hu", &num);
+
+ // Exchange bytes:
+ // 1. (num & 0xFF00) >> 8 : Move High Byte to Low Byte position
+ // 2. (num & 0x00FF) << 8 : Move Low Byte to High Byte position
+
+ swapped = ((num & 0xFF00) >> 8) | ((num & 0x00FF) << 8);
+
+ printf("Original: %hu (Hex: 0x%04X)\n", num, num);
+ printf("Swapped: %hu (Hex: 0x%04X)\n", swapped, swapped);
+
+ return 0;
+}+
\ No newline at end of file
diff --git a/Semester_1/letusc/luc108.c b/Semester_1/letusc/luc108.c
@@ -0,0 +1,37 @@
+/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Receive an 8-bit number and exchange its higher 4 bits with lower 4 bits.
+*/
+/* Let Us C, Chap- 21 (Operations on Bits), Qn No.: B(f) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int main()
+{
+ unsigned char num, swapped;
+
+ printf("Enter an 8-bit number (0-255): ");
+ scanf("%hhu", &num);
+
+ // Exchange nibbles
+ // (num & 0xF0) >> 4 : High nibble to Low
+ // (num & 0x0F) << 4 : Low nibble to High
+
+ swapped = ((num & 0xF0) >> 4) | ((num & 0x0F) << 4);
+
+ printf("Original: %d (Hex: 0x%02X)\n", num, num);
+ printf("Swapped: %d (Hex: 0x%02X)\n", swapped, swapped);
+
+ return 0;
+}+
\ No newline at end of file
diff --git a/Semester_1/letusc/luc109.c b/Semester_1/letusc/luc109.c
@@ -0,0 +1,37 @@
+/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Receive an 8-bit number and set its odd bits to 1.
+*/
+/* Let Us C, Chap- 21 (Operations on Bits), Qn No.: B(g) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int main()
+{
+ unsigned char num, res;
+
+ printf("Enter an 8-bit number: ");
+ scanf("%hhu", &num);
+
+ // Odd bits usually refer to positions 1, 3, 5, 7.
+ // Mask: 1010 1010 (binary) = 0xAA
+ // OR operation sets bits to 1.
+
+ res = num | 0xAA;
+
+ printf("Original: 0x%02X\n", num);
+ printf("Result: 0x%02X\n", res);
+
+ return 0;
+}+
\ No newline at end of file
diff --git a/Semester_1/letusc/luc110.c b/Semester_1/letusc/luc110.c
@@ -0,0 +1,43 @@
+/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Receive an 8-bit number. Check if 3rd and 5th bits are ON. If yes, put them OFF.
+*/
+/* Let Us C, Chap- 21 (Operations on Bits), Qn No.: B(h) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int main()
+{
+ unsigned char num;
+ unsigned char mask = (1 << 3) | (1 << 5); // Bits 3 and 5
+
+ printf("Enter an 8-bit number: ");
+ scanf("%hhu", &num);
+
+ if ((num & mask) == mask)
+ {
+ printf("Bits 3 and 5 are ON. Turning them OFF...\n");
+ // XOR with mask toggles 1 to 0 (since they are 1)
+ // OR: AND with complement mask (~mask)
+ num = num & ~mask;
+ }
+ else
+ {
+ printf("Bits 3 and 5 are NOT both ON. No change.\n");
+ }
+
+ printf("Final Value: %d (0x%02X)\n", num, num);
+
+ return 0;
+}+
\ No newline at end of file
diff --git a/Semester_1/letusc/luc111.c b/Semester_1/letusc/luc111.c
@@ -0,0 +1,42 @@
+/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Receive an 8-bit number. Check if 3rd and 5th bits are OFF. If yes, put them ON.
+*/
+/* Let Us C, Chap- 21 (Operations on Bits), Qn No.: B(i) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int main()
+{
+ unsigned char num;
+ unsigned char mask = (1 << 3) | (1 << 5);
+
+ printf("Enter an 8-bit number: ");
+ scanf("%hhu", &num);
+
+ // Check if bits are OFF. (num & mask) should be 0.
+ if ((num & mask) == 0)
+ {
+ printf("Bits 3 and 5 are OFF. Turning them ON...\n");
+ num = num | mask;
+ }
+ else
+ {
+ printf("Bits 3 and 5 are NOT both OFF. No change.\n");
+ }
+
+ printf("Final Value: %d (0x%02X)\n", num, num);
+
+ return 0;
+}+
\ No newline at end of file
diff --git a/Semester_1/letusc/luc112.c b/Semester_1/letusc/luc112.c
@@ -0,0 +1,52 @@
+/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Rewrite the showbits() function using the _BV macro.
+*/
+/* Let Us C, Chap- 21 (Operations on Bits), Qn No.: B(j) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+
+/* _BV(x) macro usually expands to (1 << x) */
+#define _BV(x) (1 << x)
+
+void showbits(unsigned char n);
+
+int main()
+{
+ unsigned char num;
+
+ printf("Enter an 8-bit number: ");
+ scanf("%hhu", &num);
+
+ printf("Binary representation: ");
+ showbits(num);
+ printf("\n");
+
+ return 0;
+}
+
+void showbits(unsigned char n)
+{
+ int i;
+ unsigned char mask;
+
+ for (i = 7; i >= 0; i--)
+ {
+ mask = _BV(i);
+ if ((n & mask) == 0)
+ printf("0");
+ else
+ printf("1");
+ }
+}+
\ No newline at end of file
diff --git a/Semester_1/letusc/luc113.c b/Semester_1/letusc/luc113.c
@@ -0,0 +1,87 @@
+/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Store date in a structure using bit fields (day: 5 bits, month: 4 bits, year: 12 bits). Read joining dates of 10 employees and display them sorted by year.
+*/
+/* Let Us C, Chap- 22 (Miscellaneous Features), Qn No.: C(a) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+// Define structure with bit-fields
+struct date
+{
+ unsigned int day : 5; // 1-31 takes 5 bits
+ unsigned int month : 4; // 1-12 takes 4 bits
+ unsigned int year : 12; // Sufficient for year 0-4095
+};
+
+struct employee
+{
+ char name[30];
+ struct date doj; // Date of Joining
+};
+
+int compare_dates(const void *a, const void *b);
+
+int main()
+{
+ struct employee emp[10];
+ int i;
+ // Temporary variables for input because we cannot take address of a bit-field
+ int d, m, y;
+
+ printf("Enter details for 10 employees:\n");
+ for (i = 0; i < 10; i++)
+ {
+ printf("\nEmployee %d Name: ", i + 1);
+ scanf("%s", emp[i].name);
+
+ printf("Date of Joining (dd mm yyyy): ");
+ scanf("%d %d %d", &d, &m, &y);
+
+ // Assign to bit-fields
+ emp[i].doj.day = d;
+ emp[i].doj.month = m;
+ emp[i].doj.year = y;
+ }
+
+ // Sort based on year using qsort
+ qsort(emp, 10, sizeof(struct employee), compare_dates);
+
+ printf("\n--- Employees Sorted by Joining Year ---\n");
+ for (i = 0; i < 10; i++)
+ {
+ printf("%-15s | DOJ: %02d-%02d-%d\n",
+ emp[i].name, emp[i].doj.day, emp[i].doj.month, emp[i].doj.year);
+ }
+
+ return 0;
+}
+
+int compare_dates(const void *a, const void *b)
+{
+ struct employee *e1 = (struct employee *)a;
+ struct employee *e2 = (struct employee *)b;
+
+ // Primary sort by Year
+ if (e1->doj.year != e2->doj.year)
+ return e1->doj.year - e2->doj.year;
+
+ // Secondary sort by Month
+ if (e1->doj.month != e2->doj.month)
+ return e1->doj.month - e2->doj.month;
+
+ // Tertiary sort by Day
+ return e1->doj.day - e2->doj.day;
+}+
\ No newline at end of file
diff --git a/Semester_1/letusc/luc114.c b/Semester_1/letusc/luc114.c
@@ -0,0 +1,64 @@
+/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Store insurance policy holder info (gender, minor/major, policy name, duration) using bit-fields.
+*/
+/* Let Us C, Chap- 22 (Miscellaneous Features), Qn No.: C(b) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+// Define structure with bit-fields
+struct policy_holder
+{
+ char policy_name[50];
+ unsigned int duration : 7; // 0-127 years is sufficient for policy duration
+ unsigned int gender : 1; // 0: Male, 1: Female (1 bit)
+ unsigned int status : 1; // 0: Minor, 1: Major (1 bit)
+};
+
+int main()
+{
+ struct policy_holder p;
+ int temp_gen, temp_stat, temp_dur;
+
+ printf("--- Enter Policy Holder Details ---\n");
+
+ printf("Policy Name: ");
+ scanf(" %[^\n]s", p.policy_name); // Reads string with spaces
+
+ printf("Duration (Years): ");
+ scanf("%d", &temp_dur);
+ p.duration = temp_dur;
+
+ printf("Gender (0 for Male, 1 for Female): ");
+ scanf("%d", &temp_gen);
+ p.gender = temp_gen;
+
+ printf("Status (0 for Minor, 1 for Major): ");
+ scanf("%d", &temp_stat);
+ p.status = temp_stat;
+
+ printf("\n--- Policy Information Stored ---\n");
+ printf("Policy: %s\n", p.policy_name);
+ printf("Duration: %u years\n", p.duration);
+
+ // Interpret bits for display
+ printf("Gender: %s\n", (p.gender == 1) ? "Female" : "Male");
+ printf("Status: %s\n", (p.status == 1) ? "Major" : "Minor");
+
+ printf("\nSize of structure: %zu bytes\n", sizeof(p));
+ // Note: Size will be policy_name size + padding + integer size containing the bits
+
+ return 0;
+}+
\ No newline at end of file
diff --git a/Semester_1/letusc/luc115.c b/Semester_1/letusc/luc115.c
@@ -0,0 +1,214 @@
+/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Obtain MD5 checksum of the following strings and check whether they are same:
+"Six slippery snails slid slowly seaward."
+"Six silppery snails slid slowly seaward."
+*/
+/* Let Us C, Chap- 23 (Security Programming), Qn No.: D(a) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdint.h>
+
+/* * Self-contained MD5 Implementation
+ * Based on the public domain reference implementation (RFC 1321) logic.
+ */
+
+// --- MD5 Implementation Start ---
+typedef struct {
+ uint64_t size; // Size of input in bytes
+ uint32_t buffer[4]; // Current accumulation of hash
+ uint8_t input[64]; // Input to be processed
+} MD5Context;
+
+#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
+#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
+#define H(x, y, z) ((x) ^ (y) ^ (z))
+#define I(x, y, z) ((y) ^ ((x) | (~z)))
+
+#define ROTL(x, s) (((x) << (s)) | ((x) >> (32 - (s))))
+
+#define STEP(f, a, b, c, d, x, t, s) \
+ (a) += f((b), (c), (d)) + (x) + (t); \
+ (a) = ROTL((a), (s)); \
+ (a) += (b);
+
+void md5Transform(uint32_t state[4], const uint8_t block[64]) {
+ uint32_t a = state[0], b = state[1], c = state[2], d = state[3], x[16];
+ int i, j;
+
+ // Decode block into x
+ for (i = 0, j = 0; j < 64; i++, j += 4)
+ x[i] = ((uint32_t)block[j]) | (((uint32_t)block[j + 1]) << 8) |
+ (((uint32_t)block[j + 2]) << 16) | (((uint32_t)block[j + 3]) << 24);
+
+ // Round 1
+ STEP(F, a, b, c, d, x[0], 0xd76aa478, 7);
+ STEP(F, d, a, b, c, x[1], 0xe8c7b756, 12);
+ STEP(F, c, d, a, b, x[2], 0x242070db, 17);
+ STEP(F, b, c, d, a, x[3], 0xc1bdceee, 22);
+ STEP(F, a, b, c, d, x[4], 0xf57c0faf, 7);
+ STEP(F, d, a, b, c, x[5], 0x4787c62a, 12);
+ STEP(F, c, d, a, b, x[6], 0xa8304613, 17);
+ STEP(F, b, c, d, a, x[7], 0xfd469501, 22);
+ STEP(F, a, b, c, d, x[8], 0x698098d8, 7);
+ STEP(F, d, a, b, c, x[9], 0x8b44f7af, 12);
+ STEP(F, c, d, a, b, x[10], 0xffff5bb1, 17);
+ STEP(F, b, c, d, a, x[11], 0x895cd7be, 22);
+ STEP(F, a, b, c, d, x[12], 0x6b901122, 7);
+ STEP(F, d, a, b, c, x[13], 0xfd987193, 12);
+ STEP(F, c, d, a, b, x[14], 0xa679438e, 17);
+ STEP(F, b, c, d, a, x[15], 0x49b40821, 22);
+
+ // Round 2
+ STEP(G, a, b, c, d, x[1], 0xf61e2562, 5);
+ STEP(G, d, a, b, c, x[6], 0xc040b340, 9);
+ STEP(G, c, d, a, b, x[11], 0x265e5a51, 14);
+ STEP(G, b, c, d, a, x[0], 0xe9b6c7aa, 20);
+ STEP(G, a, b, c, d, x[5], 0xd62f105d, 5);
+ STEP(G, d, a, b, c, x[10], 0x02441453, 9);
+ STEP(G, c, d, a, b, x[15], 0xd8a1e681, 14);
+ STEP(G, b, c, d, a, x[4], 0xe7d3fbc8, 20);
+ STEP(G, a, b, c, d, x[9], 0x21e1cde6, 5);
+ STEP(G, d, a, b, c, x[14], 0xc33707d6, 9);
+ STEP(G, c, d, a, b, x[3], 0xf4d50d87, 14);
+ STEP(G, b, c, d, a, x[8], 0x455a14ed, 20);
+ STEP(G, a, b, c, d, x[13], 0xa9e3e905, 5);
+ STEP(G, d, a, b, c, x[2], 0xfcefa3f8, 9);
+ STEP(G, c, d, a, b, x[7], 0x676f02d9, 14);
+ STEP(G, b, c, d, a, x[12], 0x8d2a4c8a, 20);
+
+ // Round 3
+ STEP(H, a, b, c, d, x[5], 0xfffa3942, 4);
+ STEP(H, d, a, b, c, x[8], 0x8771f681, 11);
+ STEP(H, c, d, a, b, x[11], 0x6d9d6122, 16);
+ STEP(H, b, c, d, a, x[14], 0xfde5380c, 23);
+ STEP(H, a, b, c, d, x[1], 0xa4beea44, 4);
+ STEP(H, d, a, b, c, x[4], 0x4bdecfa9, 11);
+ STEP(H, c, d, a, b, x[7], 0xf6bb4b60, 16);
+ STEP(H, b, c, d, a, x[10], 0xbebfbc70, 23);
+ STEP(H, a, b, c, d, x[13], 0x289b7ec6, 4);
+ STEP(H, d, a, b, c, x[0], 0xeaa127fa, 11);
+ STEP(H, c, d, a, b, x[3], 0xd4ef3085, 16);
+ STEP(H, b, c, d, a, x[6], 0x04881d05, 23);
+ STEP(H, a, b, c, d, x[9], 0xd9d4d039, 4);
+ STEP(H, d, a, b, c, x[12], 0xe6db99e5, 11);
+ STEP(H, c, d, a, b, x[15], 0x1fa27cf8, 16);
+ STEP(H, b, c, d, a, x[2], 0xc4ac5665, 23);
+
+ // Round 4
+ STEP(I, a, b, c, d, x[0], 0xf4292244, 6);
+ STEP(I, d, a, b, c, x[7], 0x432aff97, 10);
+ STEP(I, c, d, a, b, x[14], 0xab9423a7, 15);
+ STEP(I, b, c, d, a, x[5], 0xfc93a039, 21);
+ STEP(I, a, b, c, d, x[12], 0x655b59c3, 6);
+ STEP(I, d, a, b, c, x[3], 0x8f0ccc92, 10);
+ STEP(I, c, d, a, b, x[10], 0xffeff47d, 15);
+ STEP(I, b, c, d, a, x[1], 0x85845dd1, 21);
+ STEP(I, a, b, c, d, x[8], 0x6fa87e4f, 6);
+ STEP(I, d, a, b, c, x[15], 0xfe2ce6e0, 10);
+ STEP(I, c, d, a, b, x[6], 0xa3014314, 15);
+ STEP(I, b, c, d, a, x[13], 0x4e0811a1, 21);
+ STEP(I, a, b, c, d, x[4], 0xf7537e82, 6);
+ STEP(I, d, a, b, c, x[11], 0xbd3af235, 10);
+ STEP(I, c, d, a, b, x[2], 0x2ad7d2bb, 15);
+ STEP(I, b, c, d, a, x[9], 0xeb86d391, 21);
+
+ state[0] += a;
+ state[1] += b;
+ state[2] += c;
+ state[3] += d;
+}
+
+void md5Init(MD5Context *ctx) {
+ ctx->size = 0;
+ ctx->buffer[0] = 0x67452301;
+ ctx->buffer[1] = 0xefcdab89;
+ ctx->buffer[2] = 0x98badcfe;
+ ctx->buffer[3] = 0x10325476;
+}
+
+void md5Update(MD5Context *ctx, const uint8_t *input, size_t inputLen) {
+ size_t i, index, partLen;
+ index = (size_t)((ctx->size >> 3) & 0x3f);
+ ctx->size += (uint64_t)inputLen * 8;
+ partLen = 64 - index;
+
+ if (inputLen >= partLen) {
+ memcpy(&ctx->input[index], input, partLen);
+ md5Transform(ctx->buffer, ctx->input);
+ for (i = partLen; i + 63 < inputLen; i += 64)
+ md5Transform(ctx->buffer, &input[i]);
+ index = 0;
+ } else {
+ i = 0;
+ }
+ memcpy(&ctx->input[index], &input[i], inputLen - i);
+}
+
+void md5Final(uint8_t digest[16], MD5Context *ctx) {
+ uint8_t bits[8];
+ size_t index, padLen;
+ static const uint8_t PADDING[64] = {0x80}; // Remaining zeros implicit
+
+ // Save number of bits
+ for (int i = 0; i < 8; i++)
+ bits[i] = (uint8_t)((ctx->size >> (i * 8)) & 0xff);
+
+ index = (size_t)((ctx->size >> 3) & 0x3f);
+ padLen = (index < 56) ? (56 - index) : (120 - index);
+ md5Update(ctx, PADDING, padLen);
+ md5Update(ctx, bits, 8);
+
+ // Encode state into digest
+ for (int i = 0; i < 16; i++)
+ digest[i] = (uint8_t)((ctx->buffer[i >> 2] >> ((i & 3) * 8)) & 0xff);
+}
+// --- MD5 Implementation End ---
+
+void print_hash(uint8_t *digest) {
+ for (int i = 0; i < 16; i++) printf("%02x", digest[i]);
+ printf("\n");
+}
+
+int main() {
+ char str1[] = "Six slippery snails slid slowly seaward.";
+ char str2[] = "Six silppery snails slid slowly seaward."; // Typo 'silppery'
+
+ uint8_t hash1[16], hash2[16];
+ MD5Context ctx;
+
+ printf("String 1: %s\n", str1);
+ md5Init(&ctx);
+ md5Update(&ctx, (uint8_t*)str1, strlen(str1));
+ md5Final(hash1, &ctx);
+ printf("MD5: ");
+ print_hash(hash1);
+
+ printf("\nString 2: %s\n", str2);
+ md5Init(&ctx);
+ md5Update(&ctx, (uint8_t*)str2, strlen(str2));
+ md5Final(hash2, &ctx);
+ printf("MD5: ");
+ print_hash(hash2);
+
+ // Compare
+ int same = 1;
+ for(int i=0; i<16; i++) if(hash1[i] != hash2[i]) same = 0;
+
+ printf("\nConclusion: The MD5 checksums are %s.\n", same ? "IDENTICAL" : "DIFFERENT");
+ if (!same) printf("(Even a small change in input creates a completely different hash)\n");
+
+ return 0;
+}+
\ No newline at end of file
diff --git a/Semester_1/letusc/luc116.c b/Semester_1/letusc/luc116.c
@@ -0,0 +1,171 @@
+/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Compile any C program into a .EXE or a .out file. Obtain SHA256 checksum of the file.
+*/
+/* Let Us C, Chap- 23 (Security Programming), Qn No.: D(b) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdint.h>
+
+/* * Self-contained SHA-256 Implementation
+ * Based on FIPS 180-2 reference logic.
+ */
+
+// --- SHA256 Implementation Start ---
+typedef struct {
+ uint8_t data[64];
+ uint32_t datalen;
+ uint64_t bitlen;
+ uint32_t state[8];
+} SHA256_CTX;
+
+#define ROTRIGHT(a,b) (((a) >> (b)) | ((a) << (32-(b))))
+#define CH(x,y,z) (((x) & (y)) ^ (~(x) & (z)))
+#define MAJ(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)))
+#define EP0(x) (ROTRIGHT(x,2) ^ ROTRIGHT(x,13) ^ ROTRIGHT(x,22))
+#define EP1(x) (ROTRIGHT(x,6) ^ ROTRIGHT(x,11) ^ ROTRIGHT(x,25))
+#define SIG0(x) (ROTRIGHT(x,7) ^ ROTRIGHT(x,18) ^ ((x) >> 3))
+#define SIG1(x) (ROTRIGHT(x,17) ^ ROTRIGHT(x,19) ^ ((x) >> 10))
+
+static const uint32_t K[64] = {
+ 0x428a2f98,0x71374491,0xb5c0fbcf,0xe9b5dba5,0x3956c25b,0x59f111f1,0x923f82a4,0xab1c5ed5,
+ 0xd807aa98,0x12835b01,0x243185be,0x550c7dc3,0x72be5d74,0x80deb1fe,0x9bdc06a7,0xc19bf174,
+ 0xe49b69c1,0xefbe4786,0x0fc19dc6,0x240ca1cc,0x2de92c6f,0x4a7484aa,0x5cb0a9dc,0x76f988da,
+ 0x983e5152,0xa831c66d,0xb00327c8,0xbf597fc7,0xc6e00bf3,0xd5a79147,0x06ca6351,0x14292967,
+ 0x27b70a85,0x2e1b2138,0x4d2c6dfc,0x53380d13,0x650a7354,0x766a0abb,0x81c2c92e,0x92722c85,
+ 0xa2bfe8a1,0xa81a664b,0xc24b8b70,0xc76c51a3,0xd192e819,0xd6990624,0xf40e3585,0x106aa070,
+ 0x19a4c116,0x1e376c08,0x2748774c,0x34b0bcb5,0x391c0cb3,0x4ed8aa4a,0x5b9cca4f,0x682e6ff3,
+ 0x748f82ee,0x78a5636f,0x84c87814,0x8cc70208,0x90befffa,0xa4506ceb,0xbef9a3f7,0xc67178f2
+};
+
+void sha256_transform(SHA256_CTX *ctx, const uint8_t data[]) {
+ uint32_t a, b, c, d, e, f, g, h, i, j, t1, t2, m[64];
+
+ for (i = 0, j = 0; i < 16; ++i, j += 4)
+ m[i] = (data[j] << 24) | (data[j + 1] << 16) | (data[j + 2] << 8) | (data[j + 3]);
+ for (; i < 64; ++i)
+ m[i] = SIG1(m[i - 2]) + m[i - 7] + SIG0(m[i - 15]) + m[i - 16];
+
+ a = ctx->state[0]; b = ctx->state[1]; c = ctx->state[2]; d = ctx->state[3];
+ e = ctx->state[4]; f = ctx->state[5]; g = ctx->state[6]; h = ctx->state[7];
+
+ for (i = 0; i < 64; ++i) {
+ t1 = h + EP1(e) + CH(e, f, g) + K[i] + m[i];
+ t2 = EP0(a) + MAJ(a, b, c);
+ h = g; g = f; f = e; e = d + t1;
+ d = c; c = b; b = a; a = t1 + t2;
+ }
+
+ ctx->state[0] += a; ctx->state[1] += b; ctx->state[2] += c; ctx->state[3] += d;
+ ctx->state[4] += e; ctx->state[5] += f; ctx->state[6] += g; ctx->state[7] += h;
+}
+
+void sha256_init(SHA256_CTX *ctx) {
+ ctx->datalen = 0;
+ ctx->bitlen = 0;
+ ctx->state[0] = 0x6a09e667; ctx->state[1] = 0xbb67ae85;
+ ctx->state[2] = 0x3c6ef372; ctx->state[3] = 0xa54ff53a;
+ ctx->state[4] = 0x510e527f; ctx->state[5] = 0x9b05688c;
+ ctx->state[6] = 0x1f83d9ab; ctx->state[7] = 0x5be0cd19;
+}
+
+void sha256_update(SHA256_CTX *ctx, const uint8_t data[], size_t len) {
+ for (size_t i = 0; i < len; ++i) {
+ ctx->data[ctx->datalen] = data[i];
+ ctx->datalen++;
+ if (ctx->datalen == 64) {
+ sha256_transform(ctx, ctx->data);
+ ctx->bitlen += 512;
+ ctx->datalen = 0;
+ }
+ }
+}
+
+void sha256_final(SHA256_CTX *ctx, uint8_t hash[]) {
+ uint32_t i = ctx->datalen;
+ if (ctx->datalen < 56) {
+ ctx->data[i++] = 0x80;
+ while (i < 56) ctx->data[i++] = 0x00;
+ } else {
+ ctx->data[i++] = 0x80;
+ while (i < 64) ctx->data[i++] = 0x00;
+ sha256_transform(ctx, ctx->data);
+ memset(ctx->data, 0, 56);
+ }
+
+ ctx->bitlen += ctx->datalen * 8;
+ ctx->data[63] = ctx->bitlen;
+ ctx->data[62] = ctx->bitlen >> 8;
+ ctx->data[61] = ctx->bitlen >> 16;
+ ctx->data[60] = ctx->bitlen >> 24;
+ ctx->data[59] = ctx->bitlen >> 32;
+ ctx->data[58] = ctx->bitlen >> 40;
+ ctx->data[57] = ctx->bitlen >> 48;
+ ctx->data[56] = ctx->bitlen >> 56;
+ sha256_transform(ctx, ctx->data);
+
+ for (i = 0; i < 4; ++i) {
+ hash[i] = (ctx->state[0] >> (24 - i * 8)) & 0x000000ff;
+ hash[i + 4] = (ctx->state[1] >> (24 - i * 8)) & 0x000000ff;
+ hash[i + 8] = (ctx->state[2] >> (24 - i * 8)) & 0x000000ff;
+ hash[i + 12] = (ctx->state[3] >> (24 - i * 8)) & 0x000000ff;
+ hash[i + 16] = (ctx->state[4] >> (24 - i * 8)) & 0x000000ff;
+ hash[i + 20] = (ctx->state[5] >> (24 - i * 8)) & 0x000000ff;
+ hash[i + 24] = (ctx->state[6] >> (24 - i * 8)) & 0x000000ff;
+ hash[i + 28] = (ctx->state[7] >> (24 - i * 8)) & 0x000000ff;
+ }
+}
+// --- SHA256 Implementation End ---
+
+int main(int argc, char *argv[]) {
+ FILE *fp;
+ char filename[100];
+ uint8_t buffer[1024];
+ size_t bytesRead;
+ SHA256_CTX ctx;
+ uint8_t hash[32];
+ int i;
+
+ // Get filename
+ if (argc < 2) {
+ printf("Enter filename to checksum (e.g., this_program.exe): ");
+ scanf("%s", filename);
+ } else {
+ strcpy(filename, argv[1]);
+ }
+
+ fp = fopen(filename, "rb"); // Open in binary mode
+ if (fp == NULL) {
+ printf("Error: Could not open file '%s'\n", filename);
+ return 1;
+ }
+
+ sha256_init(&ctx);
+
+ while ((bytesRead = fread(buffer, 1, sizeof(buffer), fp)) > 0) {
+ sha256_update(&ctx, buffer, bytesRead);
+ }
+
+ sha256_final(&ctx, hash);
+ fclose(fp);
+
+ printf("SHA256 Checksum of '%s':\n", filename);
+ for (i = 0; i < 32; i++) {
+ printf("%02x", hash[i]);
+ }
+ printf("\n");
+
+ return 0;
+}+
\ No newline at end of file
diff --git a/Semester_1/letusc/luc117.c b/Semester_1/letusc/luc117.c
@@ -0,0 +1,93 @@
+/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Write a program to convert a given text into an audio file using OpenAI Audio API (TTS).
+*/
+/* Let Us C, Chap- 24 (Interaction with ChatGPT through C), Qn No.: B(a) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+/* NOTE: These programs require the 'libcurl' library to compile.
+ Command: gcc luc117.c -o output -lcurl */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <curl/curl.h>
+
+/* Pre-requisites:
+ 1. Install libcurl development package.
+ 2. Get OpenAI API Key.
+*/
+
+#define API_KEY "YOUR_OPENAI_API_KEY_HERE"
+
+size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) {
+ size_t written = fwrite(ptr, size, nmemb, stream);
+ return written;
+}
+
+int main(void) {
+ CURL *curl;
+ CURLcode res;
+ FILE *fp;
+
+ // JSON Payload construction
+ const char *url = "https://api.openai.com/v1/audio/speech";
+ const char *data = "{"
+ "\"model\": \"tts-1\","
+ "\"input\": \"Hello! This is a C program talking to you.\","
+ "\"voice\": \"alloy\""
+ "}";
+
+ struct curl_slist *headers = NULL;
+ char auth_header[100];
+ sprintf(auth_header, "Authorization: Bearer %s", API_KEY);
+
+ curl_global_init(CURL_GLOBAL_ALL);
+ curl = curl_easy_init();
+
+ if(curl) {
+ // Set Headers
+ headers = curl_slist_append(headers, "Content-Type: application/json");
+ headers = curl_slist_append(headers, auth_header);
+
+ // Open file to save audio
+ fp = fopen("output_audio.mp3", "wb");
+ if(!fp) {
+ printf("Error opening file for writing.\n");
+ return 1;
+ }
+
+ // Configure CURL
+ curl_easy_setopt(curl, CURLOPT_URL, url);
+ curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
+ curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
+ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
+ curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
+
+ // Perform Request
+ printf("Sending request to OpenAI TTS API...\n");
+ res = curl_easy_perform(curl);
+
+ if(res != CURLE_OK)
+ fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
+ else
+ printf("Audio saved to 'output_audio.mp3' successfully.\n");
+
+ // Cleanup
+ fclose(fp);
+ curl_slist_free_all(headers);
+ curl_easy_cleanup(curl);
+ }
+
+ curl_global_cleanup();
+ return 0;
+}+
\ No newline at end of file
diff --git a/Semester_1/letusc/luc118.c b/Semester_1/letusc/luc118.c
@@ -0,0 +1,72 @@
+/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Write a program to generate 4 images of birds flying in the sky with a computer's mouse in their beak using OpenAI Image API.
+*/
+/* Let Us C, Chap- 24 (Interaction with ChatGPT through C), Qn No.: B(b) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+/* NOTE: These programs require the 'libcurl' library to compile.
+ Command: gcc luc118.c -o output -lcurl */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <curl/curl.h>
+
+/* Pre-requisites:
+ 1. Install libcurl.
+ 2. Get OpenAI API Key.
+*/
+
+#define API_KEY "YOUR_OPENAI_API_KEY_HERE"
+
+int main(void) {
+ CURL *curl;
+ CURLcode res;
+
+ const char *url = "https://api.openai.com/v1/images/generations";
+
+ // JSON Payload: 4 images, 1024x1024
+ const char *data = "{"
+ "\"prompt\": \"Birds flying in the sky with a computer mouse in their beak\","
+ "\"n\": 4,"
+ "\"size\": \"1024x1024\""
+ "}";
+
+ struct curl_slist *headers = NULL;
+ char auth_header[100];
+ sprintf(auth_header, "Authorization: Bearer %s", API_KEY);
+
+ curl = curl_easy_init();
+ if(curl) {
+ headers = curl_slist_append(headers, "Content-Type: application/json");
+ headers = curl_slist_append(headers, auth_header);
+
+ curl_easy_setopt(curl, CURLOPT_URL, url);
+ curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
+ curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
+
+ // For simplicity, we print the JSON response to stdout.
+ // The response will contain URLs to the generated images.
+ printf("Sending request to OpenAI Image API...\n\n");
+ res = curl_easy_perform(curl);
+
+ if(res != CURLE_OK)
+ fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
+
+ printf("\n\nCheck the JSON output above for 'url' fields to view images.\n");
+
+ curl_slist_free_all(headers);
+ curl_easy_cleanup(curl);
+ }
+ return 0;
+}+
\ No newline at end of file
diff --git a/Semester_1/letusc/luc119.c b/Semester_1/letusc/luc119.c
@@ -0,0 +1,78 @@
+/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Write a program to analyse a given sentence to detect the mood of the sentence using OpenAI Chat Completion API.
+*/
+/* Let Us C, Chap- 24 (Interaction with ChatGPT through C), Qn No.: B(c) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+/* NOTE: These programs require the 'libcurl' library to compile.
+ Command: gcc luc119.c -o output -lcurl */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <curl/curl.h>
+
+/* Pre-requisites:
+ 1. Install libcurl.
+ 2. Get OpenAI API Key.
+*/
+
+#define API_KEY "YOUR_OPENAI_API_KEY_HERE"
+
+int main(void) {
+ CURL *curl;
+ CURLcode res;
+
+ const char *url = "https://api.openai.com/v1/chat/completions";
+
+ /* We construct the JSON payload manually.
+ System prompt instructs the model to detect mood.
+ User prompt is the sentence to analyze.
+ */
+ const char *data = "{"
+ "\"model\": \"gpt-3.5-turbo\","
+ "\"messages\": ["
+ " {\"role\": \"system\", \"content\": \"You are a helpful assistant. Analyze the mood of the user input sentence. Return only the mood keywords (e.g., admiration, appreciation, anger, joy).\"},"
+ " {\"role\": \"user\", \"content\": \"I am so impressed by your performance\"}"
+ "]"
+ "}";
+
+ struct curl_slist *headers = NULL;
+ char auth_header[100];
+ sprintf(auth_header, "Authorization: Bearer %s", API_KEY);
+
+ curl = curl_easy_init();
+ if(curl) {
+ headers = curl_slist_append(headers, "Content-Type: application/json");
+ headers = curl_slist_append(headers, auth_header);
+
+ curl_easy_setopt(curl, CURLOPT_URL, url);
+ curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
+ curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
+
+ printf("Analyzing sentence: 'I am so impressed by your performance'\n");
+ printf("Waiting for OpenAI response...\n\n");
+
+ // The response will be printed to standard output
+ res = curl_easy_perform(curl);
+
+ if(res != CURLE_OK)
+ fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
+
+ printf("\n\n(Parse the JSON above to extract the 'content' field)\n");
+
+ curl_slist_free_all(headers);
+ curl_easy_cleanup(curl);
+ }
+ return 0;
+}+
\ No newline at end of file
diff --git a/docs/index.html b/docs/index.html
@@ -11313,6 +11313,3737 @@ void convert(long n, char *suffix)
</div>
<div class="file-item flex items-center justify-between px-3 py-2 hover:bg-white hover:shadow-sm rounded-lg transition-all group border border-transparent hover:border-slate-100 mb-1">
+ <div class="flex items-center gap-2.5 min-w-0 cursor-pointer flex-1" onclick="showCode('code-Semester_1-letusc-luc078-c', 'luc078.c', 'https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc078.c')">
+ <svg class="w-4 h-4 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
+ </svg>
+ <span class="text-sm text-slate-600 font-medium group-hover:text-blue-600 truncate">luc078.c</span>
+ </div>
+ <div class="flex items-center gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
+ <a href="https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc078.c" target="_blank" class="p-1.5 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded-md" title="View on GitHub">
+ <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-2.126 1.029-2.935-.103-.253-.446-1.372.097-2.897 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.525.202 2.644.1 2.897.64.809 1.026 1.841 1.026 2.935 0 3.847-2.337 4.687-4.565 4.935.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z" clip-rule="evenodd"></path></svg>
+ </a>
+ </div>
+ <!-- Embedded Code Storage -->
+ <div id="code-Semester_1-letusc-luc078-c" style="display:none;">/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Create a structure 'student' (Roll, Name, Dept, Course, Year). Write functions to print names by join year and print data by roll number.
+*/
+/* Let Us C, Chap- 17 (Structures), Qn No.: B(a) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+struct student
+{
+ int roll;
+ char name[50];
+ char dept[20];
+ char course[20];
+ int year;
+};
+
+void print_by_year(struct student *s, int n, int year);
+void print_by_roll(struct student *s, int n, int roll);
+
+int main()
+{
+ struct student data[450] = {
+ {101, "Amit", "CS", "B.Sc", 2024},
+ {102, "Rahul", "Physics", "B.Sc", 2024},
+ {103, "Sneha", "CS", "M.Sc", 2023},
+ {104, "Priya", "Maths", "B.Sc", 2025},
+ {105, "Rohan", "CS", "B.Sc", 2024}
+ };
+ int n = 5; // Using 5 sample records
+ int year, roll;
+
+ printf("Enter year to list students: ");
+ scanf("%d", &year);
+ print_by_year(data, n, year);
+
+ printf("\nEnter roll number to find student: ");
+ scanf("%d", &roll);
+ print_by_roll(data, n, roll);
+
+ return 0;
+}
+
+void print_by_year(struct student *s, int n, int year)
+{
+ int i, found = 0;
+ printf("Students joining in %d:\n", year);
+ for (i = 0; i < n; i++)
+ {
+ if (s[i].year == year)
+ {
+ printf("- %s\n", s[i].name);
+ found = 1;
+ }
+ }
+ if (!found) printf("No students found for this year.\n");
+}
+
+void print_by_roll(struct student *s, int n, int roll)
+{
+ int i;
+ for (i = 0; i < n; i++)
+ {
+ if (s[i].roll == roll)
+ {
+ printf("\n--- Student Details ---\n");
+ printf("Roll: %d\nName: %s\nDept: %s\nCourse: %s\nYear: %d\n",
+ s[i].roll, s[i].name, s[i].dept, s[i].course, s[i].year);
+ return;
+ }
+ }
+ printf("Student with Roll %d not found.\n", roll);
+}</div>
+ </div>
+
+ <div class="file-item flex items-center justify-between px-3 py-2 hover:bg-white hover:shadow-sm rounded-lg transition-all group border border-transparent hover:border-slate-100 mb-1">
+ <div class="flex items-center gap-2.5 min-w-0 cursor-pointer flex-1" onclick="showCode('code-Semester_1-letusc-luc079-c', 'luc079.c', 'https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc079.c')">
+ <svg class="w-4 h-4 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
+ </svg>
+ <span class="text-sm text-slate-600 font-medium group-hover:text-blue-600 truncate">luc079.c</span>
+ </div>
+ <div class="flex items-center gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
+ <a href="https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc079.c" target="_blank" class="p-1.5 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded-md" title="View on GitHub">
+ <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-2.126 1.029-2.935-.103-.253-.446-1.372.097-2.897 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.525.202 2.644.1 2.897.64.809 1.026 1.841 1.026 2.935 0 3.847-2.337 4.687-4.565 4.935.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z" clip-rule="evenodd"></path></svg>
+ </a>
+ </div>
+ <!-- Embedded Code Storage -->
+ <div id="code-Semester_1-letusc-luc079-c" style="display:none;">/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Create a structure for bank customers (Acc no, Name, Balance). Write functions to print low balance customers and handle deposits/withdrawals.
+*/
+/* Let Us C, Chap- 17 (Structures), Qn No.: B(b) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+struct customer
+{
+ int acc_no;
+ char name[50];
+ float balance;
+};
+
+void print_low_balance(struct customer *c, int n);
+void transaction(struct customer *c, int n, int acc, float amount, int code);
+
+int main()
+{
+ struct customer bank[200] = {
+ {1001, "Alice", 5000.0},
+ {1002, "Bob", 500.0},
+ {1003, "Charlie", 1200.0},
+ {1004, "David", 800.0},
+ {1005, "Eve", 2000.0}
+ };
+ int n = 5;
+ int acc, code;
+ float amt;
+
+ // Task 1: Low Balance
+ printf("--- Customers with Balance < Rs. 1000 ---\n");
+ print_low_balance(bank, n);
+
+ // Task 2: Transaction
+ printf("\n--- Transaction Menu ---\n");
+ printf("Enter Account No, Amount, Code (1=Deposit, 0=Withdraw): ");
+ scanf("%d %f %d", &acc, &amt, &code);
+
+ transaction(bank, n, acc, amt, code);
+
+ return 0;
+}
+
+void print_low_balance(struct customer *c, int n)
+{
+ int i;
+ for (i = 0; i < n; i++)
+ {
+ if (c[i].balance < 1000)
+ {
+ printf("Acc: %d, Name: %s, Bal: %.2f\n", c[i].acc_no, c[i].name, c[i].balance);
+ }
+ }
+}
+
+void transaction(struct customer *c, int n, int acc, float amount, int code)
+{
+ int i, found = 0;
+ for (i = 0; i < n; i++)
+ {
+ if (c[i].acc_no == acc)
+ {
+ found = 1;
+ if (code == 1) // Deposit
+ {
+ c[i].balance += amount;
+ printf("Deposit successful. New Balance: %.2f\n", c[i].balance);
+ }
+ else if (code == 0) // Withdraw
+ {
+ if (c[i].balance - amount < 1000)
+ {
+ printf("The balance is insufficient for the specified withdrawal (Must maintain min 1000).\n");
+ }
+ else
+ {
+ c[i].balance -= amount;
+ printf("Withdrawal successful. New Balance: %.2f\n", c[i].balance);
+ }
+ }
+ else
+ {
+ printf("Invalid transaction code.\n");
+ }
+ break;
+ }
+ }
+ if (!found) printf("Account number not found.\n");
+}</div>
+ </div>
+
+ <div class="file-item flex items-center justify-between px-3 py-2 hover:bg-white hover:shadow-sm rounded-lg transition-all group border border-transparent hover:border-slate-100 mb-1">
+ <div class="flex items-center gap-2.5 min-w-0 cursor-pointer flex-1" onclick="showCode('code-Semester_1-letusc-luc080-c', 'luc080.c', 'https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc080.c')">
+ <svg class="w-4 h-4 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
+ </svg>
+ <span class="text-sm text-slate-600 font-medium group-hover:text-blue-600 truncate">luc080.c</span>
+ </div>
+ <div class="flex items-center gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
+ <a href="https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc080.c" target="_blank" class="p-1.5 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded-md" title="View on GitHub">
+ <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-2.126 1.029-2.935-.103-.253-.446-1.372.097-2.897 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.525.202 2.644.1 2.897.64.809 1.026 1.841 1.026 2.935 0 3.847-2.337 4.687-4.565 4.935.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z" clip-rule="evenodd"></path></svg>
+ </a>
+ </div>
+ <!-- Embedded Code Storage -->
+ <div id="code-Semester_1-letusc-luc080-c" style="display:none;">/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Automobile engine parts (Serial AA0-FF9, Year, Material, Qty). Retrieve parts between serial numbers BB1 and CC6.
+*/
+/* Let Us C, Chap- 17 (Structures), Qn No.: B(c) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+struct part
+{
+ char serial[4]; // 3 chars + null terminator
+ int mfg_year;
+ char material[20];
+ int quantity;
+};
+
+void retrieve_parts(struct part *p, int n);
+
+int main()
+{
+ struct part inventory[] = {
+ {"AA0", 2020, "Steel", 50},
+ {"BB2", 2021, "Aluminum", 20},
+ {"BB5", 2022, "Carbon", 10},
+ {"CC1", 2021, "Steel", 100},
+ {"CC7", 2023, "Titanium", 5},
+ {"FF9", 2024, "Iron", 60}
+ };
+ int n = 6;
+
+ printf("--- Parts with Serial Numbers between BB1 and CC6 ---\n");
+ retrieve_parts(inventory, n);
+
+ return 0;
+}
+
+void retrieve_parts(struct part *p, int n)
+{
+ int i;
+ // We compare strings lexicographically
+ char start[] = "BB1";
+ char end[] = "CC6";
+
+ for (i = 0; i < n; i++)
+ {
+ if (strcmp(p[i].serial, start) >= 0 && strcmp(p[i].serial, end) <= 0)
+ {
+ printf("Serial: %s | Year: %d | Mat: %s | Qty: %d\n",
+ p[i].serial, p[i].mfg_year, p[i].material, p[i].quantity);
+ }
+ }
+}</div>
+ </div>
+
+ <div class="file-item flex items-center justify-between px-3 py-2 hover:bg-white hover:shadow-sm rounded-lg transition-all group border border-transparent hover:border-slate-100 mb-1">
+ <div class="flex items-center gap-2.5 min-w-0 cursor-pointer flex-1" onclick="showCode('code-Semester_1-letusc-luc081-c', 'luc081.c', 'https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc081.c')">
+ <svg class="w-4 h-4 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
+ </svg>
+ <span class="text-sm text-slate-600 font-medium group-hover:text-blue-600 truncate">luc081.c</span>
+ </div>
+ <div class="flex items-center gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
+ <a href="https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc081.c" target="_blank" class="p-1.5 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded-md" title="View on GitHub">
+ <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-2.126 1.029-2.935-.103-.253-.446-1.372.097-2.897 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.525.202 2.644.1 2.897.64.809 1.026 1.841 1.026 2.935 0 3.847-2.337 4.687-4.565 4.935.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z" clip-rule="evenodd"></path></svg>
+ </a>
+ </div>
+ <!-- Embedded Code Storage -->
+ <div id="code-Semester_1-letusc-luc081-c" style="display:none;">/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Create structure for Cricketers (Name, Age, Tests, Avg Runs). Sort 20 records by average runs using qsort().
+*/
+/* Let Us C, Chap- 17 (Structures), Qn No.: B(d) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+struct cricketer
+{
+ char name[30];
+ int age;
+ int tests;
+ float avg_runs;
+};
+
+// Comparator function for qsort
+int compare(const void *a, const void *b)
+{
+ struct cricketer *c1 = (struct cricketer *)a;
+ struct cricketer *c2 = (struct cricketer *)b;
+
+ if (c1->avg_runs > c2->avg_runs) return 1;
+ else if (c1->avg_runs < c2->avg_runs) return -1;
+ else return 0;
+}
+
+int main()
+{
+ // Initializing fewer than 20 for demonstration, but logic applies to 20
+ struct cricketer team[5] = {
+ {"Kohli", 34, 110, 53.4},
+ {"Smith", 33, 95, 59.8},
+ {"Root", 32, 120, 50.1},
+ {"Sharma", 35, 80, 45.5},
+ {"Williamson", 32, 90, 54.0}
+ };
+ int n = 5, i;
+
+ printf("Before Sorting:\n");
+ for (i = 0; i < n; i++)
+ printf("%s: %.2f\n", team[i].name, team[i].avg_runs);
+
+ qsort(team, n, sizeof(struct cricketer), compare);
+
+ printf("\nAfter Sorting (Ascending Avg Runs):\n");
+ for (i = 0; i < n; i++)
+ printf("%s: %.2f\n", team[i].name, team[i].avg_runs);
+
+ return 0;
+}</div>
+ </div>
+
+ <div class="file-item flex items-center justify-between px-3 py-2 hover:bg-white hover:shadow-sm rounded-lg transition-all group border border-transparent hover:border-slate-100 mb-1">
+ <div class="flex items-center gap-2.5 min-w-0 cursor-pointer flex-1" onclick="showCode('code-Semester_1-letusc-luc082-c', 'luc082.c', 'https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc082.c')">
+ <svg class="w-4 h-4 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
+ </svg>
+ <span class="text-sm text-slate-600 font-medium group-hover:text-blue-600 truncate">luc082.c</span>
+ </div>
+ <div class="flex items-center gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
+ <a href="https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc082.c" target="_blank" class="p-1.5 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded-md" title="View on GitHub">
+ <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-2.126 1.029-2.935-.103-.253-.446-1.372.097-2.897 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.525.202 2.644.1 2.897.64.809 1.026 1.841 1.026 2.935 0 3.847-2.337 4.687-4.565 4.935.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z" clip-rule="evenodd"></path></svg>
+ </a>
+ </div>
+ <!-- Embedded Code Storage -->
+ <div id="code-Semester_1-letusc-luc082-c" style="display:none;">/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Structure 'employee' (Code, Name, Date of Joining). Display names of employees with tenure >= 3 years.
+*/
+/* Let Us C, Chap- 17 (Structures), Qn No.: B(e) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+struct date
+{
+ int day;
+ int month;
+ int year;
+};
+
+struct employee
+{
+ int code;
+ char name[30];
+ struct date doj;
+};
+
+int main()
+{
+ struct employee emp[5] = {
+ {101, "Amit", {12, 1, 2020}},
+ {102, "Sumit", {15, 8, 2023}},
+ {103, "Rina", {1, 1, 2018}},
+ {104, "Tina", {20, 5, 2022}},
+ {105, "Mina", {10, 12, 2025}}
+ };
+ int n = 5, i;
+ struct date current;
+
+ printf("Enter current date (dd mm yyyy): ");
+ scanf("%d %d %d", &current.day, &current.month, &current.year);
+
+ printf("\nEmployees with tenure >= 3 years:\n");
+ for (i = 0; i < n; i++)
+ {
+ int years = current.year - emp[i].doj.year;
+
+ // Adjust for month/day
+ if (current.month < emp[i].doj.month ||
+ (current.month == emp[i].doj.month && current.day < emp[i].doj.day))
+ {
+ years--;
+ }
+
+ if (years >= 3)
+ {
+ printf("%s (Tenure: %d years)\n", emp[i].name, years);
+ }
+ }
+
+ return 0;
+}</div>
+ </div>
+
+ <div class="file-item flex items-center justify-between px-3 py-2 hover:bg-white hover:shadow-sm rounded-lg transition-all group border border-transparent hover:border-slate-100 mb-1">
+ <div class="flex items-center gap-2.5 min-w-0 cursor-pointer flex-1" onclick="showCode('code-Semester_1-letusc-luc083-c', 'luc083.c', 'https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc083.c')">
+ <svg class="w-4 h-4 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
+ </svg>
+ <span class="text-sm text-slate-600 font-medium group-hover:text-blue-600 truncate">luc083.c</span>
+ </div>
+ <div class="flex items-center gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
+ <a href="https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc083.c" target="_blank" class="p-1.5 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded-md" title="View on GitHub">
+ <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-2.126 1.029-2.935-.103-.253-.446-1.372.097-2.897 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.525.202 2.644.1 2.897.64.809 1.026 1.841 1.026 2.935 0 3.847-2.337 4.687-4.565 4.935.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z" clip-rule="evenodd"></path></svg>
+ </a>
+ </div>
+ <!-- Embedded Code Storage -->
+ <div id="code-Semester_1-letusc-luc083-c" style="display:none;">/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Library menu-driven program (Add, Display, List by Author, List by Title, Count, List sorted).
+*/
+/* Let Us C, Chap- 17 (Structures), Qn No.: B(f) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+struct library
+{
+ int acc_no;
+ char title[50];
+ char author[50];
+ float price;
+ int is_issued; // 1 = Yes, 0 = No
+};
+
+void add_book(struct library *lib, int *count);
+void display_books(struct library *lib, int count);
+void list_by_author(struct library *lib, int count);
+void list_title_by_acc(struct library *lib, int count);
+void sort_by_acc(struct library *lib, int count);
+
+int main()
+{
+ struct library books[100];
+ int count = 0;
+ int choice;
+
+ while (1)
+ {
+ printf("\n--- Library Menu ---\n");
+ printf("1. Add Book Info\n");
+ printf("2. Display Book Info\n");
+ printf("3. List books of given author\n");
+ printf("4. List title of specified accession number\n");
+ printf("5. List count of books\n");
+ printf("6. List books in order of accession number\n");
+ printf("7. Exit\n");
+ printf("Enter choice: ");
+ scanf("%d", &choice);
+
+ switch (choice)
+ {
+ case 1: add_book(books, &count); break;
+ case 2: display_books(books, count); break;
+ case 3: list_by_author(books, count); break;
+ case 4: list_title_by_acc(books, count); break;
+ case 5: printf("Total books in library: %d\n", count); break;
+ case 6: sort_by_acc(books, count); display_books(books, count); break;
+ case 7: exit(0);
+ default: printf("Invalid choice!\n");
+ }
+ }
+ return 0;
+}
+
+void add_book(struct library *lib, int *count)
+{
+ printf("Enter Accession No, Title, Author, Price, Issued(1/0):\n");
+ scanf("%d", &lib[*count].acc_no);
+ scanf("%s", lib[*count].title); // Using %s for simplicity (no spaces)
+ scanf("%s", lib[*count].author);
+ scanf("%f", &lib[*count].price);
+ scanf("%d", &lib[*count].is_issued);
+ (*count)++;
+}
+
+void display_books(struct library *lib, int count)
+{
+ int i;
+ for (i = 0; i < count; i++)
+ printf("%d: %s by %s ($%.2f) Issued: %d\n",
+ lib[i].acc_no, lib[i].title, lib[i].author, lib[i].price, lib[i].is_issued);
+}
+
+void list_by_author(struct library *lib, int count)
+{
+ char author[50];
+ int i, found = 0;
+ printf("Enter author name: ");
+ scanf("%s", author);
+ for (i = 0; i < count; i++)
+ {
+ if (strcmp(lib[i].author, author) == 0)
+ {
+ printf("%s\n", lib[i].title);
+ found = 1;
+ }
+ }
+ if (!found) printf("No books found.\n");
+}
+
+void list_title_by_acc(struct library *lib, int count)
+{
+ int acc, i;
+ printf("Enter Accession No: ");
+ scanf("%d", &acc);
+ for (i = 0; i < count; i++)
+ {
+ if (lib[i].acc_no == acc)
+ {
+ printf("Title: %s\n", lib[i].title);
+ return;
+ }
+ }
+ printf("Book not found.\n");
+}
+
+void sort_by_acc(struct library *lib, int count)
+{
+ struct library temp;
+ int i, j;
+ for (i = 0; i < count - 1; i++)
+ {
+ for (j = 0; j < count - i - 1; j++)
+ {
+ if (lib[j].acc_no > lib[j + 1].acc_no)
+ {
+ temp = lib[j];
+ lib[j] = lib[j + 1];
+ lib[j + 1] = temp;
+ }
+ }
+ }
+}</div>
+ </div>
+
+ <div class="file-item flex items-center justify-between px-3 py-2 hover:bg-white hover:shadow-sm rounded-lg transition-all group border border-transparent hover:border-slate-100 mb-1">
+ <div class="flex items-center gap-2.5 min-w-0 cursor-pointer flex-1" onclick="showCode('code-Semester_1-letusc-luc084-c', 'luc084.c', 'https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc084.c')">
+ <svg class="w-4 h-4 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
+ </svg>
+ <span class="text-sm text-slate-600 font-medium group-hover:text-blue-600 truncate">luc084.c</span>
+ </div>
+ <div class="flex items-center gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
+ <a href="https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc084.c" target="_blank" class="p-1.5 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded-md" title="View on GitHub">
+ <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-2.126 1.029-2.935-.103-.253-.446-1.372.097-2.897 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.525.202 2.644.1 2.897.64.809 1.026 1.841 1.026 2.935 0 3.847-2.337 4.687-4.565 4.935.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z" clip-rule="evenodd"></path></svg>
+ </a>
+ </div>
+ <!-- Embedded Code Storage -->
+ <div id="code-Semester_1-letusc-luc084-c" style="display:none;">/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Define a function that compares two given dates. Return 0 if equal, otherwise return 1.
+*/
+/* Let Us C, Chap- 17 (Structures), Qn No.: B(g) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+struct date
+{
+ int day;
+ int month;
+ int year;
+};
+
+int compare_dates(struct date d1, struct date d2);
+
+int main()
+{
+ struct date date1, date2;
+
+ printf("Enter Date 1 (dd mm yyyy): ");
+ scanf("%d %d %d", &date1.day, &date1.month, &date1.year);
+
+ printf("Enter Date 2 (dd mm yyyy): ");
+ scanf("%d %d %d", &date2.day, &date2.month, &date2.year);
+
+ if (compare_dates(date1, date2) == 0)
+ printf("The dates are Equal.\n");
+ else
+ printf("The dates are NOT Equal.\n");
+
+ return 0;
+}
+
+int compare_dates(struct date d1, struct date d2)
+{
+ if (d1.day == d2.day && d1.month == d2.month && d1.year == d2.year)
+ return 0;
+ else
+ return 1;
+}</div>
+ </div>
+
+ <div class="file-item flex items-center justify-between px-3 py-2 hover:bg-white hover:shadow-sm rounded-lg transition-all group border border-transparent hover:border-slate-100 mb-1">
+ <div class="flex items-center gap-2.5 min-w-0 cursor-pointer flex-1" onclick="showCode('code-Semester_1-letusc-luc085-c', 'luc085.c', 'https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc085.c')">
+ <svg class="w-4 h-4 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
+ </svg>
+ <span class="text-sm text-slate-600 font-medium group-hover:text-blue-600 truncate">luc085.c</span>
+ </div>
+ <div class="flex items-center gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
+ <a href="https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc085.c" target="_blank" class="p-1.5 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded-md" title="View on GitHub">
+ <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-2.126 1.029-2.935-.103-.253-.446-1.372.097-2.897 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.525.202 2.644.1 2.897.64.809 1.026 1.841 1.026 2.935 0 3.847-2.337 4.687-4.565 4.935.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z" clip-rule="evenodd"></path></svg>
+ </a>
+ </div>
+ <!-- Embedded Code Storage -->
+ <div id="code-Semester_1-letusc-luc085-c" style="display:none;">/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Suppose a file contains student records (Name, Age). Write a program to read these records and display them in sorted order by name.
+*/
+/* Let Us C, Chap- 19 (File Input/Output), Qn No.: B(a) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+struct student
+{
+ char name[40];
+ int age;
+};
+
+void create_dummy_data();
+int compare_names(const void *a, const void *b);
+
+int main()
+{
+ FILE *fp;
+ struct student s[100];
+ int count = 0, i;
+
+ // Create sample file for demonstration
+ create_dummy_data();
+
+ fp = fopen("students.dat", "rb");
+ if (fp == NULL)
+ {
+ printf("Cannot open file!\n");
+ exit(1);
+ }
+
+ // Read records into array
+ while (fread(&s[count], sizeof(struct student), 1, fp) == 1)
+ {
+ count++;
+ }
+ fclose(fp);
+
+ // Sort the array
+ qsort(s, count, sizeof(struct student), compare_names);
+
+ printf("--- Student List (Sorted by Name) ---\n");
+ for (i = 0; i < count; i++)
+ {
+ printf("Name: %-20s Age: %d\n", s[i].name, s[i].age);
+ }
+
+ return 0;
+}
+
+int compare_names(const void *a, const void *b)
+{
+ return strcmp(((struct student *)a)->name, ((struct student *)b)->name);
+}
+
+void create_dummy_data()
+{
+ FILE *fp = fopen("students.dat", "wb");
+ struct student data[] = {
+ {"Zack", 20}, {"Alice", 19}, {"Bob", 21}, {"Charlie", 20}, {"Yasmine", 19}
+ };
+ if (fp)
+ {
+ fwrite(data, sizeof(struct student), 5, fp);
+ fclose(fp);
+ }
+}</div>
+ </div>
+
+ <div class="file-item flex items-center justify-between px-3 py-2 hover:bg-white hover:shadow-sm rounded-lg transition-all group border border-transparent hover:border-slate-100 mb-1">
+ <div class="flex items-center gap-2.5 min-w-0 cursor-pointer flex-1" onclick="showCode('code-Semester_1-letusc-luc086-c', 'luc086.c', 'https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc086.c')">
+ <svg class="w-4 h-4 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
+ </svg>
+ <span class="text-sm text-slate-600 font-medium group-hover:text-blue-600 truncate">luc086.c</span>
+ </div>
+ <div class="flex items-center gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
+ <a href="https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc086.c" target="_blank" class="p-1.5 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded-md" title="View on GitHub">
+ <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-2.126 1.029-2.935-.103-.253-.446-1.372.097-2.897 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.525.202 2.644.1 2.897.64.809 1.026 1.841 1.026 2.935 0 3.847-2.337 4.687-4.565 4.935.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z" clip-rule="evenodd"></path></svg>
+ </a>
+ </div>
+ <!-- Embedded Code Storage -->
+ <div id="code-Semester_1-letusc-luc086-c" style="display:none;">/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Write a program to copy contents of one file to another. While doing so replace all lowercase characters to their equivalent uppercase characters.
+*/
+/* Let Us C, Chap- 19 (File Input/Output), Qn No.: B(b) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+void create_source_file();
+
+int main()
+{
+ FILE *fs, *ft;
+ char ch;
+
+ create_source_file(); // Helper to make code runnable
+
+ fs = fopen("source.txt", "r");
+ if (fs == NULL)
+ {
+ printf("Cannot open source file.\n");
+ exit(1);
+ }
+
+ ft = fopen("target.txt", "w");
+ if (ft == NULL)
+ {
+ printf("Cannot open target file.\n");
+ fclose(fs);
+ exit(2);
+ }
+
+ while ((ch = fgetc(fs)) != EOF)
+ {
+ ch = toupper(ch);
+ fputc(ch, ft);
+ }
+
+ printf("File copied successfully with uppercase conversion.\n");
+ printf("Check 'target.txt' for results.\n");
+
+ fclose(fs);
+ fclose(ft);
+
+ return 0;
+}
+
+void create_source_file()
+{
+ FILE *fp = fopen("source.txt", "w");
+ if (fp)
+ {
+ fprintf(fp, "This is a sample text.\nIt contains Lowercase letters.\n");
+ fclose(fp);
+ }
+}</div>
+ </div>
+
+ <div class="file-item flex items-center justify-between px-3 py-2 hover:bg-white hover:shadow-sm rounded-lg transition-all group border border-transparent hover:border-slate-100 mb-1">
+ <div class="flex items-center gap-2.5 min-w-0 cursor-pointer flex-1" onclick="showCode('code-Semester_1-letusc-luc087-c', 'luc087.c', 'https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc087.c')">
+ <svg class="w-4 h-4 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
+ </svg>
+ <span class="text-sm text-slate-600 font-medium group-hover:text-blue-600 truncate">luc087.c</span>
+ </div>
+ <div class="flex items-center gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
+ <a href="https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc087.c" target="_blank" class="p-1.5 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded-md" title="View on GitHub">
+ <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-2.126 1.029-2.935-.103-.253-.446-1.372.097-2.897 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.525.202 2.644.1 2.897.64.809 1.026 1.841 1.026 2.935 0 3.847-2.337 4.687-4.565 4.935.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z" clip-rule="evenodd"></path></svg>
+ </a>
+ </div>
+ <!-- Embedded Code Storage -->
+ <div id="code-Semester_1-letusc-luc087-c" style="display:none;">/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Write a program that merges lines alternately from two files and writes the results to a new file. Handle remaining lines if file sizes differ.
+*/
+/* Let Us C, Chap- 19 (File Input/Output), Qn No.: B(c) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+void create_sample_files();
+
+int main()
+{
+ FILE *fp1, *fp2, *fp3;
+ char line1[100], line2[100];
+ char *res1, *res2;
+
+ create_sample_files();
+
+ fp1 = fopen("file1.txt", "r");
+ fp2 = fopen("file2.txt", "r");
+ fp3 = fopen("merge.txt", "w");
+
+ if (fp1 == NULL || fp2 == NULL || fp3 == NULL)
+ {
+ printf("File error.\n");
+ exit(1);
+ }
+
+ // Read lines from both files
+ res1 = fgets(line1, sizeof(line1), fp1);
+ res2 = fgets(line2, sizeof(line2), fp2);
+
+ while (res1 != NULL && res2 != NULL)
+ {
+ fputs(line1, fp3);
+ fputs(line2, fp3);
+
+ res1 = fgets(line1, sizeof(line1), fp1);
+ res2 = fgets(line2, sizeof(line2), fp2);
+ }
+
+ // Append remaining lines from file 1
+ while (res1 != NULL)
+ {
+ fputs(line1, fp3);
+ res1 = fgets(line1, sizeof(line1), fp1);
+ }
+
+ // Append remaining lines from file 2
+ while (res2 != NULL)
+ {
+ fputs(line2, fp3);
+ res2 = fgets(line2, sizeof(line2), fp2);
+ }
+
+ printf("Files merged alternately into 'merge.txt'.\n");
+
+ fclose(fp1);
+ fclose(fp2);
+ fclose(fp3);
+
+ return 0;
+}
+
+void create_sample_files()
+{
+ FILE *f1 = fopen("file1.txt", "w");
+ FILE *f2 = fopen("file2.txt", "w");
+
+ fprintf(f1, "File 1 - Line A\nFile 1 - Line B\nFile 1 - Line C\n");
+ fprintf(f2, "File 2 - Line 1\nFile 2 - Line 2\nFile 2 - Line 3\nFile 2 - Line 4\n");
+
+ fclose(f1);
+ fclose(f2);
+}</div>
+ </div>
+
+ <div class="file-item flex items-center justify-between px-3 py-2 hover:bg-white hover:shadow-sm rounded-lg transition-all group border border-transparent hover:border-slate-100 mb-1">
+ <div class="flex items-center gap-2.5 min-w-0 cursor-pointer flex-1" onclick="showCode('code-Semester_1-letusc-luc088-c', 'luc088.c', 'https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc088.c')">
+ <svg class="w-4 h-4 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
+ </svg>
+ <span class="text-sm text-slate-600 font-medium group-hover:text-blue-600 truncate">luc088.c</span>
+ </div>
+ <div class="flex items-center gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
+ <a href="https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc088.c" target="_blank" class="p-1.5 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded-md" title="View on GitHub">
+ <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-2.126 1.029-2.935-.103-.253-.446-1.372.097-2.897 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.525.202 2.644.1 2.897.64.809 1.026 1.841 1.026 2.935 0 3.847-2.337 4.687-4.565 4.935.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z" clip-rule="evenodd"></path></svg>
+ </a>
+ </div>
+ <!-- Embedded Code Storage -->
+ <div id="code-Semester_1-letusc-luc088-c" style="display:none;">/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Write a program to encrypt/decrypt a file using: (1) Offset cipher (2) Substitution cipher.
+*/
+/* Let Us C, Chap- 19 (File Input/Output), Qn No.: B(d) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+void create_plain_file();
+
+int main()
+{
+ FILE *fs, *ft;
+ char ch;
+ int choice;
+
+ create_plain_file();
+
+ printf("1. Offset Cipher\n2. Substitution Cipher\nEnter choice: ");
+ scanf("%d", &choice);
+
+ fs = fopen("plain.txt", "r");
+ ft = fopen("coded.txt", "w");
+
+ if (fs == NULL || ft == NULL)
+ {
+ printf("Error opening files.\n");
+ exit(1);
+ }
+
+ while ((ch = fgetc(fs)) != EOF)
+ {
+ if (choice == 1)
+ {
+ // Offset Cipher: Add 128 (effectively shifts char code)
+ fputc(ch + 10, ft); // Using +10 for visibility, problem says 128
+ }
+ else
+ {
+ // Simple Substitution: A->!, B->@ etc.
+ // Here, we'll just map any char to char+5 for simplicity
+ // as true substitution requires a full map array.
+ fputc(ch + 5, ft);
+ }
+ }
+
+ printf("Encryption complete. Check 'coded.txt'.\n");
+
+ fclose(fs);
+ fclose(ft);
+ return 0;
+}
+
+void create_plain_file()
+{
+ FILE *fp = fopen("plain.txt", "w");
+ if (fp)
+ {
+ fprintf(fp, "SECRET MESSAGE");
+ fclose(fp);
+ }
+}</div>
+ </div>
+
+ <div class="file-item flex items-center justify-between px-3 py-2 hover:bg-white hover:shadow-sm rounded-lg transition-all group border border-transparent hover:border-slate-100 mb-1">
+ <div class="flex items-center gap-2.5 min-w-0 cursor-pointer flex-1" onclick="showCode('code-Semester_1-letusc-luc089-c', 'luc089.c', 'https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc089.c')">
+ <svg class="w-4 h-4 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
+ </svg>
+ <span class="text-sm text-slate-600 font-medium group-hover:text-blue-600 truncate">luc089.c</span>
+ </div>
+ <div class="flex items-center gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
+ <a href="https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc089.c" target="_blank" class="p-1.5 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded-md" title="View on GitHub">
+ <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-2.126 1.029-2.935-.103-.253-.446-1.372.097-2.897 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.525.202 2.644.1 2.897.64.809 1.026 1.841 1.026 2.935 0 3.847-2.337 4.687-4.565 4.935.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z" clip-rule="evenodd"></path></svg>
+ </a>
+ </div>
+ <!-- Embedded Code Storage -->
+ <div id="code-Semester_1-letusc-luc089-c" style="display:none;">/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Update 'CUSTOMER.DAT' balance using 'TRANSACTIONS.DAT' (Deposit/Withdrawal). Ensure balance doesn't fall below Rs. 100 on withdrawal.
+*/
+/* Let Us C, Chap- 19 (File Input/Output), Qn No.: B(e) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+struct customer {
+ int accno;
+ char name[30];
+ float balance;
+};
+
+struct trans {
+ int accno;
+ char trans_type;
+ float amount;
+};
+
+void create_files();
+void update_customer(struct customer *c, int n, struct trans t);
+
+int main()
+{
+ FILE *fc, *ft;
+ struct customer cust[100];
+ struct trans t;
+ int i, n_cust = 0;
+
+ create_files(); // Generate dummy data
+
+ // 1. Load all customers into memory
+ fc = fopen("CUSTOMER.DAT", "rb");
+ if (fc == NULL) exit(1);
+
+ while (fread(&cust[n_cust], sizeof(struct customer), 1, fc) == 1)
+ {
+ n_cust++;
+ }
+ fclose(fc);
+
+ // 2. Process transactions sequentially
+ ft = fopen("TRANSACTIONS.DAT", "rb");
+ if (ft == NULL) exit(2);
+
+ printf("Processing Transactions...\n");
+ while (fread(&t, sizeof(struct trans), 1, ft) == 1)
+ {
+ update_customer(cust, n_cust, t);
+ }
+ fclose(ft);
+
+ // 3. Write updated data back to CUSTOMER.DAT
+ fc = fopen("CUSTOMER.DAT", "wb");
+ fwrite(cust, sizeof(struct customer), n_cust, fc);
+ fclose(fc);
+
+ printf("Update Complete. New Balances:\n");
+ for(i=0; i<n_cust; i++)
+ printf("%d %s: %.2f\n", cust[i].accno, cust[i].name, cust[i].balance);
+
+ return 0;
+}
+
+void update_customer(struct customer *c, int n, struct trans t)
+{
+ int i;
+ for (i = 0; i < n; i++)
+ {
+ if (c[i].accno == t.accno)
+ {
+ if (t.trans_type == 'D')
+ {
+ c[i].balance += t.amount;
+ printf("Acc %d: Deposited %.2f\n", t.accno, t.amount);
+ }
+ else if (t.trans_type == 'W')
+ {
+ if ((c[i].balance - t.amount) >= 100)
+ {
+ c[i].balance -= t.amount;
+ printf("Acc %d: Withdrew %.2f\n", t.accno, t.amount);
+ }
+ else
+ {
+ printf("Acc %d: Withdrawal denied (Min bal constraint)\n", t.accno);
+ }
+ }
+ return;
+ }
+ }
+ printf("Transaction Error: Acc %d not found\n", t.accno);
+}
+
+void create_files()
+{
+ struct customer c[] = {{101, "A", 500}, {102, "B", 1000}, {103, "C", 200}};
+ struct trans t[] = {{101, 'D', 200}, {102, 'W', 500}, {103, 'W', 150}}; // 103 fail
+ FILE *f1 = fopen("CUSTOMER.DAT", "wb");
+ FILE *f2 = fopen("TRANSACTIONS.DAT", "wb");
+ fwrite(c, sizeof(struct customer), 3, f1);
+ fwrite(t, sizeof(struct trans), 3, f2);
+ fclose(f1); fclose(f2);
+}</div>
+ </div>
+
+ <div class="file-item flex items-center justify-between px-3 py-2 hover:bg-white hover:shadow-sm rounded-lg transition-all group border border-transparent hover:border-slate-100 mb-1">
+ <div class="flex items-center gap-2.5 min-w-0 cursor-pointer flex-1" onclick="showCode('code-Semester_1-letusc-luc090-c', 'luc090.c', 'https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc090.c')">
+ <svg class="w-4 h-4 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
+ </svg>
+ <span class="text-sm text-slate-600 font-medium group-hover:text-blue-600 truncate">luc090.c</span>
+ </div>
+ <div class="flex items-center gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
+ <a href="https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc090.c" target="_blank" class="p-1.5 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded-md" title="View on GitHub">
+ <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-2.126 1.029-2.935-.103-.253-.446-1.372.097-2.897 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.525.202 2.644.1 2.897.64.809 1.026 1.841 1.026 2.935 0 3.847-2.337 4.687-4.565 4.935.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z" clip-rule="evenodd"></path></svg>
+ </a>
+ </div>
+ <!-- Embedded Code Storage -->
+ <div id="code-Semester_1-letusc-luc090-c" style="display:none;">/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Read employee records (code, name, date, salary), sort them by Date of Joining, and write to a target file.
+*/
+/* Let Us C, Chap- 19 (File Input/Output), Qn No.: B(f) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+struct date { int d, m, y; };
+struct employee {
+ int empcode[6]; // Not used as int array usually, likely int id. Assuming int code.
+ char empname[20];
+ struct date join_date;
+ float salary;
+};
+
+// Redefining struct for easier usage assuming empcode is int
+struct emp_clean {
+ int code;
+ char name[20];
+ struct date doj;
+ float salary;
+};
+
+void create_emp_file();
+int compare_dates(const void *a, const void *b);
+
+int main()
+{
+ FILE *fp, *ft;
+ struct emp_clean e[50];
+ int count = 0, i;
+
+ create_emp_file();
+
+ fp = fopen("employee.dat", "rb");
+ if (!fp) return 1;
+
+ while (fread(&e[count], sizeof(struct emp_clean), 1, fp) == 1)
+ count++;
+ fclose(fp);
+
+ qsort(e, count, sizeof(struct emp_clean), compare_dates);
+
+ ft = fopen("emp_sorted.dat", "wb");
+ fwrite(e, sizeof(struct emp_clean), count, ft);
+ fclose(ft);
+
+ printf("Sorted records written to 'emp_sorted.dat'.\nDisplaying sorted list:\n");
+ for(i=0; i<count; i++)
+ printf("%s - %02d/%02d/%04d\n", e[i].name, e[i].doj.d, e[i].doj.m, e[i].doj.y);
+
+ return 0;
+}
+
+int compare_dates(const void *a, const void *b)
+{
+ struct emp_clean *e1 = (struct emp_clean *)a;
+ struct emp_clean *e2 = (struct emp_clean *)b;
+
+ if (e1->doj.y != e2->doj.y) return e1->doj.y - e2->doj.y;
+ if (e1->doj.m != e2->doj.m) return e1->doj.m - e2->doj.m;
+ return e1->doj.d - e2->doj.d;
+}
+
+void create_emp_file()
+{
+ struct emp_clean data[] = {
+ {1, "John", {12, 5, 2022}, 5000},
+ {2, "Jane", {10, 1, 2020}, 6000}, // Senior
+ {3, "Bob", {15, 8, 2021}, 5500}
+ };
+ FILE *f = fopen("employee.dat", "wb");
+ fwrite(data, sizeof(struct emp_clean), 3, f);
+ fclose(f);
+}</div>
+ </div>
+
+ <div class="file-item flex items-center justify-between px-3 py-2 hover:bg-white hover:shadow-sm rounded-lg transition-all group border border-transparent hover:border-slate-100 mb-1">
+ <div class="flex items-center gap-2.5 min-w-0 cursor-pointer flex-1" onclick="showCode('code-Semester_1-letusc-luc091-c', 'luc091.c', 'https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc091.c')">
+ <svg class="w-4 h-4 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
+ </svg>
+ <span class="text-sm text-slate-600 font-medium group-hover:text-blue-600 truncate">luc091.c</span>
+ </div>
+ <div class="flex items-center gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
+ <a href="https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc091.c" target="_blank" class="p-1.5 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded-md" title="View on GitHub">
+ <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-2.126 1.029-2.935-.103-.253-.446-1.372.097-2.897 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.525.202 2.644.1 2.897.64.809 1.026 1.841 1.026 2.935 0 3.847-2.337 4.687-4.565 4.935.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z" clip-rule="evenodd"></path></svg>
+ </a>
+ </div>
+ <!-- Embedded Code Storage -->
+ <div id="code-Semester_1-letusc-luc091-c" style="display:none;">/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Read 'blood donors' file (Name, Address, Age, Blood Type). Print donors with Age < 25 and Blood Type 2.
+*/
+/* Let Us C, Chap- 19 (File Input/Output), Qn No.: B(g) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+struct donor {
+ char name[21]; // 20 cols + null
+ char address[41]; // 40 cols + null
+ int age; // 2 cols -> int
+ int blood_type; // 1 col -> int
+};
+
+void create_donor_file();
+
+int main()
+{
+ FILE *fp;
+ struct donor d;
+
+ create_donor_file();
+
+ fp = fopen("donors.dat", "rb");
+ if (!fp)
+ {
+ printf("File error.\n");
+ exit(1);
+ }
+
+ printf("--- Donors (Age < 25, Type 2) ---\n");
+ while (fread(&d, sizeof(struct donor), 1, fp) == 1)
+ {
+ if (d.age < 25 && d.blood_type == 2)
+ {
+ printf("Name: %s | Age: %d | Addr: %s\n", d.name, d.age, d.address);
+ }
+ }
+
+ fclose(fp);
+ return 0;
+}
+
+void create_donor_file()
+{
+ struct donor data[] = {
+ {"Amit", "Delhi", 22, 2}, // Match
+ {"Rahul", "Mumbai", 30, 2}, // Old
+ {"Sumit", "Pune", 21, 1}, // Wrong type
+ {"Priya", "Goa", 24, 2} // Match
+ };
+ FILE *f = fopen("donors.dat", "wb");
+ fwrite(data, sizeof(struct donor), 4, f);
+ fclose(f);
+}</div>
+ </div>
+
+ <div class="file-item flex items-center justify-between px-3 py-2 hover:bg-white hover:shadow-sm rounded-lg transition-all group border border-transparent hover:border-slate-100 mb-1">
+ <div class="flex items-center gap-2.5 min-w-0 cursor-pointer flex-1" onclick="showCode('code-Semester_1-letusc-luc092-c', 'luc092.c', 'https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc092.c')">
+ <svg class="w-4 h-4 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
+ </svg>
+ <span class="text-sm text-slate-600 font-medium group-hover:text-blue-600 truncate">luc092.c</span>
+ </div>
+ <div class="flex items-center gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
+ <a href="https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc092.c" target="_blank" class="p-1.5 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded-md" title="View on GitHub">
+ <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-2.126 1.029-2.935-.103-.253-.446-1.372.097-2.897 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.525.202 2.644.1 2.897.64.809 1.026 1.841 1.026 2.935 0 3.847-2.337 4.687-4.565 4.935.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z" clip-rule="evenodd"></path></svg>
+ </a>
+ </div>
+ <!-- Embedded Code Storage -->
+ <div id="code-Semester_1-letusc-luc092-c" style="display:none;">/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Write a program to store names in a file. Display the n-th name in the list, where n is read from the keyboard.
+*/
+/* Let Us C, Chap- 19 (File Input/Output), Qn No.: B(h) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+void create_name_file();
+
+int main()
+{
+ FILE *fp;
+ char name[50];
+ int n, current = 0, found = 0;
+
+ create_name_file();
+
+ printf("Enter value of n to find n-th name: ");
+ scanf("%d", &n);
+
+ fp = fopen("names.txt", "r");
+ if (!fp) exit(1);
+
+ // Assuming one name per line
+ while (fgets(name, sizeof(name), fp) != NULL)
+ {
+ current++;
+ if (current == n)
+ {
+ printf("The %d-th name is: %s", n, name);
+ found = 1;
+ break;
+ }
+ }
+
+ if (!found)
+ printf("Record not found (Only %d names exist).\n", current);
+
+ fclose(fp);
+ return 0;
+}
+
+void create_name_file()
+{
+ FILE *f = fopen("names.txt", "w");
+ fprintf(f, "Alice\nBob\nCharlie\nDavid\nEve\nFrank\n");
+ fclose(f);
+}</div>
+ </div>
+
+ <div class="file-item flex items-center justify-between px-3 py-2 hover:bg-white hover:shadow-sm rounded-lg transition-all group border border-transparent hover:border-slate-100 mb-1">
+ <div class="flex items-center gap-2.5 min-w-0 cursor-pointer flex-1" onclick="showCode('code-Semester_1-letusc-luc093-c', 'luc093.c', 'https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc093.c')">
+ <svg class="w-4 h-4 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
+ </svg>
+ <span class="text-sm text-slate-600 font-medium group-hover:text-blue-600 truncate">luc093.c</span>
+ </div>
+ <div class="flex items-center gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
+ <a href="https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc093.c" target="_blank" class="p-1.5 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded-md" title="View on GitHub">
+ <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-2.126 1.029-2.935-.103-.253-.446-1.372.097-2.897 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.525.202 2.644.1 2.897.64.809 1.026 1.841 1.026 2.935 0 3.847-2.337 4.687-4.565 4.935.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z" clip-rule="evenodd"></path></svg>
+ </a>
+ </div>
+ <!-- Embedded Code Storage -->
+ <div id="code-Semester_1-letusc-luc093-c" style="display:none;">/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Update Master file (Roll, Name) using Transaction file (Roll, Code Add/Delete). Both files are sorted by Roll.
+*/
+/* Let Us C, Chap- 19 (File Input/Output), Qn No.: B(i) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+struct student {
+ int roll;
+ char name[30];
+};
+
+struct trans {
+ int roll;
+ char code; // 'A' for Add, 'D' for Delete
+ char name[30]; // Only needed for Add
+};
+
+void create_files();
+
+int main()
+{
+ FILE *fm, *ft, *fn;
+ struct student m;
+ struct trans t;
+ int has_m, has_t;
+
+ create_files();
+
+ fm = fopen("MASTER.DAT", "rb");
+ ft = fopen("TRANS_ROLL.DAT", "rb");
+ fn = fopen("NEW_MASTER.DAT", "wb");
+
+ if (!fm || !ft || !fn) exit(1);
+
+ has_m = fread(&m, sizeof(struct student), 1, fm);
+ has_t = fread(&t, sizeof(struct trans), 1, ft);
+
+ printf("Merging Master and Transaction files...\n");
+
+ while (has_m && has_t)
+ {
+ if (m.roll < t.roll)
+ {
+ // No transaction for this master record, keep it
+ fwrite(&m, sizeof(struct student), 1, fn);
+ has_m = fread(&m, sizeof(struct student), 1, fm);
+ }
+ else if (m.roll == t.roll)
+ {
+ // Transaction affects this record
+ if (t.code == 'D')
+ {
+ printf("Deleting Roll %d\n", m.roll);
+ // Skip writing 'm' to file (Deleting)
+ has_m = fread(&m, sizeof(struct student), 1, fm);
+ }
+ else
+ {
+ // Logic error: Can't ADD if ID exists. Maybe Update?
+ // Assuming replace or skip. Let's skip T and keep M for now.
+ has_m = fread(&m, sizeof(struct student), 1, fm);
+ }
+ has_t = fread(&t, sizeof(struct trans), 1, ft);
+ }
+ else // m.roll > t.roll
+ {
+ // Transaction ID is new
+ if (t.code == 'A')
+ {
+ struct student new_s;
+ new_s.roll = t.roll;
+ strcpy(new_s.name, t.name);
+ fwrite(&new_s, sizeof(struct student), 1, fn);
+ printf("Adding Roll %d\n", new_s.roll);
+ }
+ has_t = fread(&t, sizeof(struct trans), 1, ft);
+ }
+ }
+
+ // Process remaining Master
+ while (has_m)
+ {
+ fwrite(&m, sizeof(struct student), 1, fn);
+ has_m = fread(&m, sizeof(struct student), 1, fm);
+ }
+
+ // Process remaining Transactions (Only Adds)
+ while (has_t)
+ {
+ if (t.code == 'A')
+ {
+ struct student new_s = {t.roll, ""};
+ strcpy(new_s.name, t.name);
+ fwrite(&new_s, sizeof(struct student), 1, fn);
+ printf("Adding Roll %d\n", new_s.roll);
+ }
+ has_t = fread(&t, sizeof(struct trans), 1, ft);
+ }
+
+ fclose(fm); fclose(ft); fclose(fn);
+ return 0;
+}
+
+void create_files()
+{
+ struct student m[] = {{10, "A"}, {20, "B"}, {30, "C"}};
+ struct trans t[] = {{15, 'A', "NewGuy"}, {20, 'D', ""}, {40, 'A', "LastGuy"}};
+
+ FILE *f1 = fopen("MASTER.DAT", "wb");
+ fwrite(m, sizeof(struct student), 3, f1);
+ fclose(f1);
+
+ FILE *f2 = fopen("TRANS_ROLL.DAT", "wb");
+ fwrite(t, sizeof(struct trans), 3, f2);
+ fclose(f2);
+}</div>
+ </div>
+
+ <div class="file-item flex items-center justify-between px-3 py-2 hover:bg-white hover:shadow-sm rounded-lg transition-all group border border-transparent hover:border-slate-100 mb-1">
+ <div class="flex items-center gap-2.5 min-w-0 cursor-pointer flex-1" onclick="showCode('code-Semester_1-letusc-luc094-c', 'luc094.c', 'https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc094.c')">
+ <svg class="w-4 h-4 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
+ </svg>
+ <span class="text-sm text-slate-600 font-medium group-hover:text-blue-600 truncate">luc094.c</span>
+ </div>
+ <div class="flex items-center gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
+ <a href="https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc094.c" target="_blank" class="p-1.5 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded-md" title="View on GitHub">
+ <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-2.126 1.029-2.935-.103-.253-.446-1.372.097-2.897 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.525.202 2.644.1 2.897.64.809 1.026 1.841 1.026 2.935 0 3.847-2.337 4.687-4.565 4.935.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z" clip-rule="evenodd"></path></svg>
+ </a>
+ </div>
+ <!-- Embedded Code Storage -->
+ <div id="code-Semester_1-letusc-luc094-c" style="display:none;">/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Read a text file, delete the words 'a', 'the', 'an' and replace each with a blank space. Write to new file.
+*/
+/* Let Us C, Chap- 19 (File Input/Output), Qn No.: B(j) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+void create_article_file();
+
+int main()
+{
+ FILE *fp, *ft;
+ char word[100];
+
+ create_article_file();
+
+ fp = fopen("articles.txt", "r");
+ ft = fopen("clean.txt", "w");
+
+ if (!fp || !ft) exit(1);
+
+ // Basic word-by-word processing using fscanf
+ // Note: fscanf skips whitespace, so original spacing formatting
+ // might be lost, but it effectively filters words.
+
+ while (fscanf(fp, "%s", word) != EOF)
+ {
+ if (strcasecmp(word, "a") == 0 ||
+ strcasecmp(word, "an") == 0 ||
+ strcasecmp(word, "the") == 0)
+ {
+ fputc(' ', ft); // Replace with blank
+ }
+ else
+ {
+ fprintf(ft, "%s ", word);
+ }
+ }
+
+ printf("Processed file. Articles removed in 'clean.txt'.\n");
+
+ fclose(fp);
+ fclose(ft);
+ return 0;
+}
+
+void create_article_file()
+{
+ FILE *f = fopen("articles.txt", "w");
+ fprintf(f, "The quick brown fox jumps over a lazy dog. It was an honour.");
+ fclose(f);
+}</div>
+ </div>
+
+ <div class="file-item flex items-center justify-between px-3 py-2 hover:bg-white hover:shadow-sm rounded-lg transition-all group border border-transparent hover:border-slate-100 mb-1">
+ <div class="flex items-center gap-2.5 min-w-0 cursor-pointer flex-1" onclick="showCode('code-Semester_1-letusc-luc095-c', 'luc095.c', 'https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc095.c')">
+ <svg class="w-4 h-4 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
+ </svg>
+ <span class="text-sm text-slate-600 font-medium group-hover:text-blue-600 truncate">luc095.c</span>
+ </div>
+ <div class="flex items-center gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
+ <a href="https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc095.c" target="_blank" class="p-1.5 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded-md" title="View on GitHub">
+ <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-2.126 1.029-2.935-.103-.253-.446-1.372.097-2.897 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.525.202 2.644.1 2.897.64.809 1.026 1.841 1.026 2.935 0 3.847-2.337 4.687-4.565 4.935.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z" clip-rule="evenodd"></path></svg>
+ </a>
+ </div>
+ <!-- Embedded Code Storage -->
+ <div id="code-Semester_1-letusc-luc095-c" style="display:none;">/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Write a program that can read a file and display its contents. The file name should be supplied as a command-line argument.
+*/
+/* Let Us C, Chap- 20 (More Issues In Input/Output), Qn No.: A(a) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+int main(int argc, char *argv[])
+{
+ FILE *fp;
+ char ch;
+
+ /* Check if file name is provided */
+ if (argc != 2)
+ {
+ printf("Usage: %s <filename>\n", argv[0]);
+ exit(1);
+ }
+
+ fp = fopen(argv[1], "r");
+ if (fp == NULL)
+ {
+ printf("Error: Cannot open file '%s'\n", argv[1]);
+ exit(2);
+ }
+
+ /* Read and display contents */
+ while ((ch = fgetc(fp)) != EOF)
+ {
+ printf("%c", ch);
+ }
+
+ fclose(fp);
+ return 0;
+}</div>
+ </div>
+
+ <div class="file-item flex items-center justify-between px-3 py-2 hover:bg-white hover:shadow-sm rounded-lg transition-all group border border-transparent hover:border-slate-100 mb-1">
+ <div class="flex items-center gap-2.5 min-w-0 cursor-pointer flex-1" onclick="showCode('code-Semester_1-letusc-luc096-c', 'luc096.c', 'https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc096.c')">
+ <svg class="w-4 h-4 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
+ </svg>
+ <span class="text-sm text-slate-600 font-medium group-hover:text-blue-600 truncate">luc096.c</span>
+ </div>
+ <div class="flex items-center gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
+ <a href="https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc096.c" target="_blank" class="p-1.5 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded-md" title="View on GitHub">
+ <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-2.126 1.029-2.935-.103-.253-.446-1.372.097-2.897 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.525.202 2.644.1 2.897.64.809 1.026 1.841 1.026 2.935 0 3.847-2.337 4.687-4.565 4.935.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z" clip-rule="evenodd"></path></svg>
+ </a>
+ </div>
+ <!-- Embedded Code Storage -->
+ <div id="code-Semester_1-letusc-luc096-c" style="display:none;">/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Write a program that can copy the contents of one file to another. The source and target filenames should be supplied as command-line arguments.
+*/
+/* Let Us C, Chap- 20 (More Issues In Input/Output), Qn No.: A(b) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+int main(int argc, char *argv[])
+{
+ FILE *fs, *ft;
+ char ch;
+
+ /* Check for correct number of arguments */
+ if (argc != 3)
+ {
+ printf("Usage: %s <source_file> <target_file>\n", argv[0]);
+ exit(1);
+ }
+
+ fs = fopen(argv[1], "r");
+ if (fs == NULL)
+ {
+ printf("Error: Cannot open source file '%s'\n", argv[1]);
+ exit(2);
+ }
+
+ ft = fopen(argv[2], "w");
+ if (ft == NULL)
+ {
+ printf("Error: Cannot create target file '%s'\n", argv[2]);
+ fclose(fs);
+ exit(3);
+ }
+
+ /* Copy contents */
+ while ((ch = fgetc(fs)) != EOF)
+ {
+ fputc(ch, ft);
+ }
+
+ printf("File copied successfully.\n");
+
+ fclose(fs);
+ fclose(ft);
+ return 0;
+}</div>
+ </div>
+
+ <div class="file-item flex items-center justify-between px-3 py-2 hover:bg-white hover:shadow-sm rounded-lg transition-all group border border-transparent hover:border-slate-100 mb-1">
+ <div class="flex items-center gap-2.5 min-w-0 cursor-pointer flex-1" onclick="showCode('code-Semester_1-letusc-luc097-c', 'luc097.c', 'https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc097.c')">
+ <svg class="w-4 h-4 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
+ </svg>
+ <span class="text-sm text-slate-600 font-medium group-hover:text-blue-600 truncate">luc097.c</span>
+ </div>
+ <div class="flex items-center gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
+ <a href="https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc097.c" target="_blank" class="p-1.5 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded-md" title="View on GitHub">
+ <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-2.126 1.029-2.935-.103-.253-.446-1.372.097-2.897 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.525.202 2.644.1 2.897.64.809 1.026 1.841 1.026 2.935 0 3.847-2.337 4.687-4.565 4.935.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z" clip-rule="evenodd"></path></svg>
+ </a>
+ </div>
+ <!-- Embedded Code Storage -->
+ <div id="code-Semester_1-letusc-luc097-c" style="display:none;">/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Write a program using command-line arguments to search for a word in a file and replace it with the specified word.\nUsage: change <old word> <new word> <filename>
+*/
+/* Let Us C, Chap- 20 (More Issues In Input/Output), Qn No.: A(c) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+void replace_all(char *str, const char *old_w, const char *new_w, FILE *ft);
+
+int main(int argc, char *argv[])
+{
+ FILE *fp, *ft;
+ char line[1000];
+ char *old_word, *new_word, *filename;
+
+ if (argc != 4)
+ {
+ printf("Usage: %s <old word> <new word> <filename>\n", argv[0]);
+ exit(1);
+ }
+
+ old_word = argv[1];
+ new_word = argv[2];
+ filename = argv[3];
+
+ fp = fopen(filename, "r");
+ if (fp == NULL)
+ {
+ printf("Error opening file: %s\n", filename);
+ exit(2);
+ }
+
+ // Create a temporary file
+ ft = fopen("temp.tmp", "w");
+ if (ft == NULL)
+ {
+ printf("Error creating temporary file.\n");
+ fclose(fp);
+ exit(3);
+ }
+
+ // Process line by line
+ while (fgets(line, sizeof(line), fp))
+ {
+ replace_all(line, old_word, new_word, ft);
+ }
+
+ fclose(fp);
+ fclose(ft);
+
+ // Replace original file with updated file
+ remove(filename);
+ rename("temp.tmp", filename);
+
+ printf("Replacement complete.\n");
+
+ return 0;
+}
+
+void replace_all(char *str, const char *old_w, const char *new_w, FILE *ft)
+{
+ char *pos, temp[1000];
+ int index = 0;
+ int old_len = strlen(old_w);
+
+ /* We cannot easily modify 'str' in place because new_w
+ might be larger than old_w. We write directly to file.
+ */
+
+ while ((pos = strstr(str, old_w)) != NULL)
+ {
+ // Write everything before the match
+ while (str < pos)
+ {
+ fputc(*str, ft);
+ str++;
+ }
+
+ // Write the new word
+ fputs(new_w, ft);
+
+ // Skip the old word in the source string
+ str += old_len;
+ }
+
+ // Write the remainder of the line
+ fputs(str, ft);
+}</div>
+ </div>
+
+ <div class="file-item flex items-center justify-between px-3 py-2 hover:bg-white hover:shadow-sm rounded-lg transition-all group border border-transparent hover:border-slate-100 mb-1">
+ <div class="flex items-center gap-2.5 min-w-0 cursor-pointer flex-1" onclick="showCode('code-Semester_1-letusc-luc098-c', 'luc098.c', 'https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc098.c')">
+ <svg class="w-4 h-4 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
+ </svg>
+ <span class="text-sm text-slate-600 font-medium group-hover:text-blue-600 truncate">luc098.c</span>
+ </div>
+ <div class="flex items-center gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
+ <a href="https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc098.c" target="_blank" class="p-1.5 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded-md" title="View on GitHub">
+ <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-2.126 1.029-2.935-.103-.253-.446-1.372.097-2.897 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.525.202 2.644.1 2.897.64.809 1.026 1.841 1.026 2.935 0 3.847-2.337 4.687-4.565 4.935.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z" clip-rule="evenodd"></path></svg>
+ </a>
+ </div>
+ <!-- Embedded Code Storage -->
+ <div id="code-Semester_1-letusc-luc098-c" style="display:none;">/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Write a calculator utility using command line arguments.\nUsage: calc <switch> <n> <m>\nwhere switch is arithmetic operator or comparison operator.
+*/
+/* Let Us C, Chap- 20 (More Issues In Input/Output), Qn No.: A(d) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+int main(int argc, char *argv[])
+{
+ float n, m, res;
+ char operator;
+
+ if (argc != 4)
+ {
+ printf("Usage: %s <switch> <n> <m>\n", argv[0]);
+ printf("Example: %s + 10 20\n", argv[0]);
+ printf("Note: For multiplication (*), use '*' or x to avoid shell expansion.\n");
+ exit(1);
+ }
+
+ operator = argv[1][0]; // First character of the switch argument
+ n = atof(argv[2]);
+ m = atof(argv[3]);
+
+ switch (operator)
+ {
+ // Arithmetic
+ case '+':
+ printf("%.2f\n", n + m);
+ break;
+ case '-':
+ printf("%.2f\n", n - m);
+ break;
+ case 'x':
+ case '*':
+ printf("%.2f\n", n * m);
+ break;
+ case '/':
+ if (m == 0) printf("Error: Division by zero\n");
+ else printf("%.2f\n", n / m);
+ break;
+ case '%':
+ printf("%d\n", (int)n % (int)m);
+ break;
+
+ // Comparison
+ case '<':
+ printf("%s\n", (n < m) ? "True" : "False");
+ break;
+ case '>':
+ printf("%s\n", (n > m) ? "True" : "False");
+ break;
+
+ // Handling symbols that might be multi-char (e.g. <=, >=, ==) is tricky
+ // with argv[1][0], but basic logic for typical single char switches:
+ case '=':
+ printf("%s\n", (n == m) ? "True" : "False");
+ break;
+
+ default:
+ printf("Unknown operator: %c\n", operator);
+ break;
+ }
+
+ return 0;
+}</div>
+ </div>
+
+ <div class="file-item flex items-center justify-between px-3 py-2 hover:bg-white hover:shadow-sm rounded-lg transition-all group border border-transparent hover:border-slate-100 mb-1">
+ <div class="flex items-center gap-2.5 min-w-0 cursor-pointer flex-1" onclick="showCode('code-Semester_1-letusc-luc099-c', 'luc099.c', 'https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc099.c')">
+ <svg class="w-4 h-4 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
+ </svg>
+ <span class="text-sm text-slate-600 font-medium group-hover:text-blue-600 truncate">luc099.c</span>
+ </div>
+ <div class="flex items-center gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
+ <a href="https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc099.c" target="_blank" class="p-1.5 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded-md" title="View on GitHub">
+ <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-2.126 1.029-2.935-.103-.253-.446-1.372.097-2.897 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.525.202 2.644.1 2.897.64.809 1.026 1.841 1.026 2.935 0 3.847-2.337 4.687-4.565 4.935.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z" clip-rule="evenodd"></path></svg>
+ </a>
+ </div>
+ <!-- Embedded Code Storage -->
+ <div id="code-Semester_1-letusc-luc099-c" style="display:none;">/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Read an integer 'game' representing sports won by a college. Determine if it won the 'Champion of Champions' trophy (>5 games) and list games won.
+*/
+/* Let Us C, Chap- 21 (Operations on Bits), Qn No.: A(a) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int main()
+{
+ int game;
+ int count = 0, i;
+ const char *sports[] = {
+ "Cricket", "Basketball", "Football", "Hockey",
+ "Lawn Tennis", "Table Tennis", "Carom", "Chess", "Volleyball" // Added one for bit 8
+ };
+
+ printf("Enter the game information (integer): ");
+ scanf("%d", &game);
+
+ printf("\nGames won:\n");
+ for (i = 0; i <= 8; i++)
+ {
+ if (game & (1 << i))
+ {
+ printf("- %s\n", sports[i]);
+ count++;
+ }
+ }
+
+ printf("\nTotal games won: %d\n", count);
+
+ if (count >= 5)
+ printf("Result: The college won the Champion of Champions trophy.\n");
+ else
+ printf("Result: The college did NOT win the trophy.\n");
+
+ return 0;
+}</div>
+ </div>
+
+ <div class="file-item flex items-center justify-between px-3 py-2 hover:bg-white hover:shadow-sm rounded-lg transition-all group border border-transparent hover:border-slate-100 mb-1">
+ <div class="flex items-center gap-2.5 min-w-0 cursor-pointer flex-1" onclick="showCode('code-Semester_1-letusc-luc100-c', 'luc100.c', 'https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc100.c')">
+ <svg class="w-4 h-4 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
+ </svg>
+ <span class="text-sm text-slate-600 font-medium group-hover:text-blue-600 truncate">luc100.c</span>
+ </div>
+ <div class="flex items-center gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
+ <a href="https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc100.c" target="_blank" class="p-1.5 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded-md" title="View on GitHub">
+ <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-2.126 1.029-2.935-.103-.253-.446-1.372.097-2.897 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.525.202 2.644.1 2.897.64.809 1.026 1.841 1.026 2.935 0 3.847-2.337 4.687-4.565 4.935.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z" clip-rule="evenodd"></path></svg>
+ </a>
+ </div>
+ <!-- Embedded Code Storage -->
+ <div id="code-Semester_1-letusc-luc100-c" style="display:none;">/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Determine if an animal is Carnivore/Herbivore and its type (Canine, Feline, Cetacean, Marsupial) based on bits in an integer.
+*/
+/* Let Us C, Chap- 21 (Operations on Bits), Qn No.: A(b) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+
+struct animal
+{
+ char name[30];
+ int type;
+};
+
+int main()
+{
+ struct animal a = {"OCELOT", 18};
+ int type = a.type;
+
+ printf("Animal: %s\n", a.name);
+
+ // Check Bit 4 for Diet (Assuming 1=Carnivore, 0=Herbivore based on context)
+ if (type & (1 << 4))
+ printf("Diet: Carnivore\n");
+ else
+ printf("Diet: Herbivore\n");
+
+ // Check Bits 0-3 for Family
+ printf("Family: ");
+ if (type & (1 << 0)) printf("Canine ");
+ if (type & (1 << 1)) printf("Feline ");
+ if (type & (1 << 2)) printf("Cetacean ");
+ if (type & (1 << 3)) printf("Marsupial ");
+ printf("\n");
+
+ return 0;
+}</div>
+ </div>
+
+ <div class="file-item flex items-center justify-between px-3 py-2 hover:bg-white hover:shadow-sm rounded-lg transition-all group border border-transparent hover:border-slate-100 mb-1">
+ <div class="flex items-center gap-2.5 min-w-0 cursor-pointer flex-1" onclick="showCode('code-Semester_1-letusc-luc101-c', 'luc101.c', 'https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc101.c')">
+ <svg class="w-4 h-4 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
+ </svg>
+ <span class="text-sm text-slate-600 font-medium group-hover:text-blue-600 truncate">luc101.c</span>
+ </div>
+ <div class="flex items-center gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
+ <a href="https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc101.c" target="_blank" class="p-1.5 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded-md" title="View on GitHub">
+ <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-2.126 1.029-2.935-.103-.253-.446-1.372.097-2.897 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.525.202 2.644.1 2.897.64.809 1.026 1.841 1.026 2.935 0 3.847-2.337 4.687-4.565 4.935.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z" clip-rule="evenodd"></path></svg>
+ </a>
+ </div>
+ <!-- Embedded Code Storage -->
+ <div id="code-Semester_1-letusc-luc101-c" style="display:none;">/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Decode student information (Year, Stream, Room No) packed into an integer array.
+*/
+/* Let Us C, Chap- 21 (Operations on Bits), Qn No.: A(c) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int main()
+{
+ int data[] = {273, 548, 786, 1096};
+ int n = 4, i;
+ int val, year, stream_bits, room;
+
+ for (i = 0; i < n; i++)
+ {
+ val = data[i];
+
+ // Room Number: Rest of the bits (Assuming starting from bit 8)
+ room = val >> 8;
+
+ printf("Student %d (Raw: %d):\n", i + 1, val);
+ printf(" Room No: %d\n", room);
+
+ // Year: Bits 0-3
+ printf(" Year: ");
+ if (val & (1 << 0)) printf("1st Year");
+ else if (val & (1 << 1)) printf("2nd Year");
+ else if (val & (1 << 2)) printf("3rd Year");
+ else if (val & (1 << 3)) printf("4th Year");
+ else printf("Unknown");
+ printf("\n");
+
+ // Stream: Bits 4-7 (Mech, Chem, Elec, CS)
+ printf(" Stream: ");
+ if (val & (1 << 4)) printf("Mechanical");
+ else if (val & (1 << 5)) printf("Chemical");
+ else if (val & (1 << 6)) printf("Electronics");
+ else if (val & (1 << 7)) printf("CS");
+ else printf("Unknown");
+ printf("\n\n");
+ }
+
+ return 0;
+}</div>
+ </div>
+
+ <div class="file-item flex items-center justify-between px-3 py-2 hover:bg-white hover:shadow-sm rounded-lg transition-all group border border-transparent hover:border-slate-100 mb-1">
+ <div class="flex items-center gap-2.5 min-w-0 cursor-pointer flex-1" onclick="showCode('code-Semester_1-letusc-luc102-c', 'luc102.c', 'https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc102.c')">
+ <svg class="w-4 h-4 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
+ </svg>
+ <span class="text-sm text-slate-600 font-medium group-hover:text-blue-600 truncate">luc102.c</span>
+ </div>
+ <div class="flex items-center gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
+ <a href="https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc102.c" target="_blank" class="p-1.5 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded-md" title="View on GitHub">
+ <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-2.126 1.029-2.935-.103-.253-.446-1.372.097-2.897 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.525.202 2.644.1 2.897.64.809 1.026 1.841 1.026 2.935 0 3.847-2.337 4.687-4.565 4.935.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z" clip-rule="evenodd"></path></svg>
+ </a>
+ </div>
+ <!-- Embedded Code Storage -->
+ <div id="code-Semester_1-letusc-luc102-c" style="display:none;">/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* What will be the output of the provided program segment involving bitwise operators?
+*/
+/* Let Us C, Chap- 21 (Operations on Bits), Qn No.: A(d) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int main()
+{
+ int i = 32, j = 65, k, l, m, n, o, p;
+
+ k = i | 35;
+ l = ~k;
+ m = i & j;
+ n = j ^ 32;
+ o = j << 2;
+ p = i >> 5;
+
+ printf("k = %d l = %d m = %d\n", k, l, m);
+ printf("n = %d o = %d p = %d\n", n, o, p);
+
+ return 0;
+}</div>
+ </div>
+
+ <div class="file-item flex items-center justify-between px-3 py-2 hover:bg-white hover:shadow-sm rounded-lg transition-all group border border-transparent hover:border-slate-100 mb-1">
+ <div class="flex items-center gap-2.5 min-w-0 cursor-pointer flex-1" onclick="showCode('code-Semester_1-letusc-luc103-c', 'luc103.c', 'https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc103.c')">
+ <svg class="w-4 h-4 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
+ </svg>
+ <span class="text-sm text-slate-600 font-medium group-hover:text-blue-600 truncate">luc103.c</span>
+ </div>
+ <div class="flex items-center gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
+ <a href="https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc103.c" target="_blank" class="p-1.5 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded-md" title="View on GitHub">
+ <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-2.126 1.029-2.935-.103-.253-.446-1.372.097-2.897 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.525.202 2.644.1 2.897.64.809 1.026 1.841 1.026 2.935 0 3.847-2.337 4.687-4.565 4.935.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z" clip-rule="evenodd"></path></svg>
+ </a>
+ </div>
+ <!-- Embedded Code Storage -->
+ <div id="code-Semester_1-letusc-luc103-c" style="display:none;">/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* What is the hexadecimal equivalent of the following binary numbers?
+*/
+/* Let Us C, Chap- 21 (Operations on Bits), Qn No.: B(a) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int main()
+{
+ // Binary numbers represented as string literals for reference
+ // 01011010
+ // 11000011
+ // 1010101001110101
+ // 111100001011010
+
+ printf("Binary: 01011010 -> Hex: 0x%X\n", 0b01011010);
+ printf("Binary: 11000011 -> Hex: 0x%X\n", 0b11000011);
+ printf("Binary: 1010101001110101 -> Hex: 0x%X\n", 0b1010101001110101);
+ printf("Binary: 111100001011010 -> Hex: 0x%X\n", 0b111100001011010);
+
+ /* Note: Binary literals (0b...) are a standard C extension (GCC) and part of C23 standard. */
+
+ return 0;
+}</div>
+ </div>
+
+ <div class="file-item flex items-center justify-between px-3 py-2 hover:bg-white hover:shadow-sm rounded-lg transition-all group border border-transparent hover:border-slate-100 mb-1">
+ <div class="flex items-center gap-2.5 min-w-0 cursor-pointer flex-1" onclick="showCode('code-Semester_1-letusc-luc104-c', 'luc104.c', 'https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc104.c')">
+ <svg class="w-4 h-4 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
+ </svg>
+ <span class="text-sm text-slate-600 font-medium group-hover:text-blue-600 truncate">luc104.c</span>
+ </div>
+ <div class="flex items-center gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
+ <a href="https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc104.c" target="_blank" class="p-1.5 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded-md" title="View on GitHub">
+ <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-2.126 1.029-2.935-.103-.253-.446-1.372.097-2.897 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.525.202 2.644.1 2.897.64.809 1.026 1.841 1.026 2.935 0 3.847-2.337 4.687-4.565 4.935.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z" clip-rule="evenodd"></path></svg>
+ </a>
+ </div>
+ <!-- Embedded Code Storage -->
+ <div id="code-Semester_1-letusc-luc104-c" style="display:none;">/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Rewrite expressions using bitwise compound assignment operators.
+*/
+/* Let Us C, Chap- 21 (Operations on Bits), Qn No.: B(b) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int main()
+{
+ int a = 10, b = 20, c = 5;
+
+ printf("Original values: a=%d, b=%d, c=%d\n", a, b, c);
+
+ // a = a | 3
+ a |= 3;
+ printf("a |= 3 -> %d\n", a);
+
+ // a = a & 0x48
+ a &= 0x48;
+ printf("a &= 0x48 -> %d\n", a);
+
+ // b = b ^ 0x22
+ b ^= 0x22;
+ printf("b ^= 0x22 -> %d\n", b);
+
+ // c = c << 2
+ c <<= 2;
+ printf("c <<= 2 -> %d\n", c);
+
+ return 0;
+}</div>
+ </div>
+
+ <div class="file-item flex items-center justify-between px-3 py-2 hover:bg-white hover:shadow-sm rounded-lg transition-all group border border-transparent hover:border-slate-100 mb-1">
+ <div class="flex items-center gap-2.5 min-w-0 cursor-pointer flex-1" onclick="showCode('code-Semester_1-letusc-luc105-c', 'luc105.c', 'https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc105.c')">
+ <svg class="w-4 h-4 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
+ </svg>
+ <span class="text-sm text-slate-600 font-medium group-hover:text-blue-600 truncate">luc105.c</span>
+ </div>
+ <div class="flex items-center gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
+ <a href="https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc105.c" target="_blank" class="p-1.5 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded-md" title="View on GitHub">
+ <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-2.126 1.029-2.935-.103-.253-.446-1.372.097-2.897 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.525.202 2.644.1 2.897.64.809 1.026 1.841 1.026 2.935 0 3.847-2.337 4.687-4.565 4.935.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z" clip-rule="evenodd"></path></svg>
+ </a>
+ </div>
+ <!-- Embedded Code Storage -->
+ <div id="code-Semester_1-letusc-luc105-c" style="display:none;">/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Write a function checkbits(x, p, n) which returns true if all 'n' bits starting from position 'p' are turned on.
+*/
+/* Let Us C, Chap- 21 (Operations on Bits), Qn No.: B(c) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int checkbits(unsigned int x, int p, int n);
+
+int main()
+{
+ unsigned int x;
+ int p, n;
+
+ printf("Enter number (x): ");
+ scanf("%u", &x);
+ printf("Enter starting position (p) and count (n): ");
+ scanf("%d %d", &p, &n);
+
+ if (checkbits(x, p, n))
+ printf("TRUE: %d bits starting at %d are ON.\n", n, p);
+ else
+ printf("FALSE: Not all specified bits are ON.\n");
+
+ return 0;
+}
+
+int checkbits(unsigned int x, int p, int n)
+{
+ unsigned int mask;
+
+ // Create a mask of n 1s. E.g., if n=3, mask=000...0111
+ mask = (1 << n) - 1;
+
+ // Shift mask to position p
+ mask = mask << p;
+
+ // Check if bits in x match the mask
+ return (x & mask) == mask;
+}</div>
+ </div>
+
+ <div class="file-item flex items-center justify-between px-3 py-2 hover:bg-white hover:shadow-sm rounded-lg transition-all group border border-transparent hover:border-slate-100 mb-1">
+ <div class="flex items-center gap-2.5 min-w-0 cursor-pointer flex-1" onclick="showCode('code-Semester_1-letusc-luc106-c', 'luc106.c', 'https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc106.c')">
+ <svg class="w-4 h-4 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
+ </svg>
+ <span class="text-sm text-slate-600 font-medium group-hover:text-blue-600 truncate">luc106.c</span>
+ </div>
+ <div class="flex items-center gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
+ <a href="https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc106.c" target="_blank" class="p-1.5 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded-md" title="View on GitHub">
+ <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-2.126 1.029-2.935-.103-.253-.446-1.372.097-2.897 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.525.202 2.644.1 2.897.64.809 1.026 1.841 1.026 2.935 0 3.847-2.337 4.687-4.565 4.935.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z" clip-rule="evenodd"></path></svg>
+ </a>
+ </div>
+ <!-- Embedded Code Storage -->
+ <div id="code-Semester_1-letusc-luc106-c" style="display:none;">/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Write a program to scan an 8-bit number and check whether its 3rd, 6th and 7th bit is on.
+*/
+/* Let Us C, Chap- 21 (Operations on Bits), Qn No.: B(d) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int main()
+{
+ unsigned char num;
+
+ printf("Enter an 8-bit integer (0-255): ");
+ scanf("%hhu", &num);
+
+ // Checking bits 3, 6, 7.
+ // Assuming 0-based indexing: 3rd bit is index 3 (value 8), 6th is index 6 (64), 7th is index 7 (128).
+
+ unsigned char mask = (1 << 3) | (1 << 6) | (1 << 7);
+
+ if ((num & mask) == mask)
+ printf("Bits 3, 6, and 7 are ALL ON.\n");
+ else
+ printf("Bits 3, 6, and 7 are NOT all on.\n");
+
+ return 0;
+}</div>
+ </div>
+
+ <div class="file-item flex items-center justify-between px-3 py-2 hover:bg-white hover:shadow-sm rounded-lg transition-all group border border-transparent hover:border-slate-100 mb-1">
+ <div class="flex items-center gap-2.5 min-w-0 cursor-pointer flex-1" onclick="showCode('code-Semester_1-letusc-luc107-c', 'luc107.c', 'https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc107.c')">
+ <svg class="w-4 h-4 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
+ </svg>
+ <span class="text-sm text-slate-600 font-medium group-hover:text-blue-600 truncate">luc107.c</span>
+ </div>
+ <div class="flex items-center gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
+ <a href="https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc107.c" target="_blank" class="p-1.5 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded-md" title="View on GitHub">
+ <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-2.126 1.029-2.935-.103-.253-.446-1.372.097-2.897 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.525.202 2.644.1 2.897.64.809 1.026 1.841 1.026 2.935 0 3.847-2.337 4.687-4.565 4.935.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z" clip-rule="evenodd"></path></svg>
+ </a>
+ </div>
+ <!-- Embedded Code Storage -->
+ <div id="code-Semester_1-letusc-luc107-c" style="display:none;">/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Receive an unsigned 16-bit integer and exchange the contents of its 2 bytes using bitwise operators.
+*/
+/* Let Us C, Chap- 21 (Operations on Bits), Qn No.: B(e) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int main()
+{
+ unsigned short num, swapped;
+
+ printf("Enter a 16-bit number (0-65535): ");
+ scanf("%hu", &num);
+
+ // Exchange bytes:
+ // 1. (num & 0xFF00) >> 8 : Move High Byte to Low Byte position
+ // 2. (num & 0x00FF) << 8 : Move Low Byte to High Byte position
+
+ swapped = ((num & 0xFF00) >> 8) | ((num & 0x00FF) << 8);
+
+ printf("Original: %hu (Hex: 0x%04X)\n", num, num);
+ printf("Swapped: %hu (Hex: 0x%04X)\n", swapped, swapped);
+
+ return 0;
+}</div>
+ </div>
+
+ <div class="file-item flex items-center justify-between px-3 py-2 hover:bg-white hover:shadow-sm rounded-lg transition-all group border border-transparent hover:border-slate-100 mb-1">
+ <div class="flex items-center gap-2.5 min-w-0 cursor-pointer flex-1" onclick="showCode('code-Semester_1-letusc-luc108-c', 'luc108.c', 'https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc108.c')">
+ <svg class="w-4 h-4 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
+ </svg>
+ <span class="text-sm text-slate-600 font-medium group-hover:text-blue-600 truncate">luc108.c</span>
+ </div>
+ <div class="flex items-center gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
+ <a href="https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc108.c" target="_blank" class="p-1.5 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded-md" title="View on GitHub">
+ <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-2.126 1.029-2.935-.103-.253-.446-1.372.097-2.897 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.525.202 2.644.1 2.897.64.809 1.026 1.841 1.026 2.935 0 3.847-2.337 4.687-4.565 4.935.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z" clip-rule="evenodd"></path></svg>
+ </a>
+ </div>
+ <!-- Embedded Code Storage -->
+ <div id="code-Semester_1-letusc-luc108-c" style="display:none;">/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Receive an 8-bit number and exchange its higher 4 bits with lower 4 bits.
+*/
+/* Let Us C, Chap- 21 (Operations on Bits), Qn No.: B(f) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int main()
+{
+ unsigned char num, swapped;
+
+ printf("Enter an 8-bit number (0-255): ");
+ scanf("%hhu", &num);
+
+ // Exchange nibbles
+ // (num & 0xF0) >> 4 : High nibble to Low
+ // (num & 0x0F) << 4 : Low nibble to High
+
+ swapped = ((num & 0xF0) >> 4) | ((num & 0x0F) << 4);
+
+ printf("Original: %d (Hex: 0x%02X)\n", num, num);
+ printf("Swapped: %d (Hex: 0x%02X)\n", swapped, swapped);
+
+ return 0;
+}</div>
+ </div>
+
+ <div class="file-item flex items-center justify-between px-3 py-2 hover:bg-white hover:shadow-sm rounded-lg transition-all group border border-transparent hover:border-slate-100 mb-1">
+ <div class="flex items-center gap-2.5 min-w-0 cursor-pointer flex-1" onclick="showCode('code-Semester_1-letusc-luc109-c', 'luc109.c', 'https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc109.c')">
+ <svg class="w-4 h-4 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
+ </svg>
+ <span class="text-sm text-slate-600 font-medium group-hover:text-blue-600 truncate">luc109.c</span>
+ </div>
+ <div class="flex items-center gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
+ <a href="https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc109.c" target="_blank" class="p-1.5 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded-md" title="View on GitHub">
+ <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-2.126 1.029-2.935-.103-.253-.446-1.372.097-2.897 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.525.202 2.644.1 2.897.64.809 1.026 1.841 1.026 2.935 0 3.847-2.337 4.687-4.565 4.935.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z" clip-rule="evenodd"></path></svg>
+ </a>
+ </div>
+ <!-- Embedded Code Storage -->
+ <div id="code-Semester_1-letusc-luc109-c" style="display:none;">/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Receive an 8-bit number and set its odd bits to 1.
+*/
+/* Let Us C, Chap- 21 (Operations on Bits), Qn No.: B(g) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int main()
+{
+ unsigned char num, res;
+
+ printf("Enter an 8-bit number: ");
+ scanf("%hhu", &num);
+
+ // Odd bits usually refer to positions 1, 3, 5, 7.
+ // Mask: 1010 1010 (binary) = 0xAA
+ // OR operation sets bits to 1.
+
+ res = num | 0xAA;
+
+ printf("Original: 0x%02X\n", num);
+ printf("Result: 0x%02X\n", res);
+
+ return 0;
+}</div>
+ </div>
+
+ <div class="file-item flex items-center justify-between px-3 py-2 hover:bg-white hover:shadow-sm rounded-lg transition-all group border border-transparent hover:border-slate-100 mb-1">
+ <div class="flex items-center gap-2.5 min-w-0 cursor-pointer flex-1" onclick="showCode('code-Semester_1-letusc-luc110-c', 'luc110.c', 'https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc110.c')">
+ <svg class="w-4 h-4 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
+ </svg>
+ <span class="text-sm text-slate-600 font-medium group-hover:text-blue-600 truncate">luc110.c</span>
+ </div>
+ <div class="flex items-center gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
+ <a href="https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc110.c" target="_blank" class="p-1.5 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded-md" title="View on GitHub">
+ <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-2.126 1.029-2.935-.103-.253-.446-1.372.097-2.897 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.525.202 2.644.1 2.897.64.809 1.026 1.841 1.026 2.935 0 3.847-2.337 4.687-4.565 4.935.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z" clip-rule="evenodd"></path></svg>
+ </a>
+ </div>
+ <!-- Embedded Code Storage -->
+ <div id="code-Semester_1-letusc-luc110-c" style="display:none;">/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Receive an 8-bit number. Check if 3rd and 5th bits are ON. If yes, put them OFF.
+*/
+/* Let Us C, Chap- 21 (Operations on Bits), Qn No.: B(h) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int main()
+{
+ unsigned char num;
+ unsigned char mask = (1 << 3) | (1 << 5); // Bits 3 and 5
+
+ printf("Enter an 8-bit number: ");
+ scanf("%hhu", &num);
+
+ if ((num & mask) == mask)
+ {
+ printf("Bits 3 and 5 are ON. Turning them OFF...\n");
+ // XOR with mask toggles 1 to 0 (since they are 1)
+ // OR: AND with complement mask (~mask)
+ num = num & ~mask;
+ }
+ else
+ {
+ printf("Bits 3 and 5 are NOT both ON. No change.\n");
+ }
+
+ printf("Final Value: %d (0x%02X)\n", num, num);
+
+ return 0;
+}</div>
+ </div>
+
+ <div class="file-item flex items-center justify-between px-3 py-2 hover:bg-white hover:shadow-sm rounded-lg transition-all group border border-transparent hover:border-slate-100 mb-1">
+ <div class="flex items-center gap-2.5 min-w-0 cursor-pointer flex-1" onclick="showCode('code-Semester_1-letusc-luc111-c', 'luc111.c', 'https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc111.c')">
+ <svg class="w-4 h-4 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
+ </svg>
+ <span class="text-sm text-slate-600 font-medium group-hover:text-blue-600 truncate">luc111.c</span>
+ </div>
+ <div class="flex items-center gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
+ <a href="https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc111.c" target="_blank" class="p-1.5 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded-md" title="View on GitHub">
+ <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-2.126 1.029-2.935-.103-.253-.446-1.372.097-2.897 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.525.202 2.644.1 2.897.64.809 1.026 1.841 1.026 2.935 0 3.847-2.337 4.687-4.565 4.935.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z" clip-rule="evenodd"></path></svg>
+ </a>
+ </div>
+ <!-- Embedded Code Storage -->
+ <div id="code-Semester_1-letusc-luc111-c" style="display:none;">/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Receive an 8-bit number. Check if 3rd and 5th bits are OFF. If yes, put them ON.
+*/
+/* Let Us C, Chap- 21 (Operations on Bits), Qn No.: B(i) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int main()
+{
+ unsigned char num;
+ unsigned char mask = (1 << 3) | (1 << 5);
+
+ printf("Enter an 8-bit number: ");
+ scanf("%hhu", &num);
+
+ // Check if bits are OFF. (num & mask) should be 0.
+ if ((num & mask) == 0)
+ {
+ printf("Bits 3 and 5 are OFF. Turning them ON...\n");
+ num = num | mask;
+ }
+ else
+ {
+ printf("Bits 3 and 5 are NOT both OFF. No change.\n");
+ }
+
+ printf("Final Value: %d (0x%02X)\n", num, num);
+
+ return 0;
+}</div>
+ </div>
+
+ <div class="file-item flex items-center justify-between px-3 py-2 hover:bg-white hover:shadow-sm rounded-lg transition-all group border border-transparent hover:border-slate-100 mb-1">
+ <div class="flex items-center gap-2.5 min-w-0 cursor-pointer flex-1" onclick="showCode('code-Semester_1-letusc-luc112-c', 'luc112.c', 'https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc112.c')">
+ <svg class="w-4 h-4 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
+ </svg>
+ <span class="text-sm text-slate-600 font-medium group-hover:text-blue-600 truncate">luc112.c</span>
+ </div>
+ <div class="flex items-center gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
+ <a href="https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc112.c" target="_blank" class="p-1.5 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded-md" title="View on GitHub">
+ <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-2.126 1.029-2.935-.103-.253-.446-1.372.097-2.897 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.525.202 2.644.1 2.897.64.809 1.026 1.841 1.026 2.935 0 3.847-2.337 4.687-4.565 4.935.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z" clip-rule="evenodd"></path></svg>
+ </a>
+ </div>
+ <!-- Embedded Code Storage -->
+ <div id="code-Semester_1-letusc-luc112-c" style="display:none;">/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Rewrite the showbits() function using the _BV macro.
+*/
+/* Let Us C, Chap- 21 (Operations on Bits), Qn No.: B(j) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+
+/* _BV(x) macro usually expands to (1 << x) */
+#define _BV(x) (1 << x)
+
+void showbits(unsigned char n);
+
+int main()
+{
+ unsigned char num;
+
+ printf("Enter an 8-bit number: ");
+ scanf("%hhu", &num);
+
+ printf("Binary representation: ");
+ showbits(num);
+ printf("\n");
+
+ return 0;
+}
+
+void showbits(unsigned char n)
+{
+ int i;
+ unsigned char mask;
+
+ for (i = 7; i >= 0; i--)
+ {
+ mask = _BV(i);
+ if ((n & mask) == 0)
+ printf("0");
+ else
+ printf("1");
+ }
+}</div>
+ </div>
+
+ <div class="file-item flex items-center justify-between px-3 py-2 hover:bg-white hover:shadow-sm rounded-lg transition-all group border border-transparent hover:border-slate-100 mb-1">
+ <div class="flex items-center gap-2.5 min-w-0 cursor-pointer flex-1" onclick="showCode('code-Semester_1-letusc-luc113-c', 'luc113.c', 'https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc113.c')">
+ <svg class="w-4 h-4 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
+ </svg>
+ <span class="text-sm text-slate-600 font-medium group-hover:text-blue-600 truncate">luc113.c</span>
+ </div>
+ <div class="flex items-center gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
+ <a href="https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc113.c" target="_blank" class="p-1.5 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded-md" title="View on GitHub">
+ <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-2.126 1.029-2.935-.103-.253-.446-1.372.097-2.897 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.525.202 2.644.1 2.897.64.809 1.026 1.841 1.026 2.935 0 3.847-2.337 4.687-4.565 4.935.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z" clip-rule="evenodd"></path></svg>
+ </a>
+ </div>
+ <!-- Embedded Code Storage -->
+ <div id="code-Semester_1-letusc-luc113-c" style="display:none;">/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Store date in a structure using bit fields (day: 5 bits, month: 4 bits, year: 12 bits). Read joining dates of 10 employees and display them sorted by year.
+*/
+/* Let Us C, Chap- 22 (Miscellaneous Features), Qn No.: C(a) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+// Define structure with bit-fields
+struct date
+{
+ unsigned int day : 5; // 1-31 takes 5 bits
+ unsigned int month : 4; // 1-12 takes 4 bits
+ unsigned int year : 12; // Sufficient for year 0-4095
+};
+
+struct employee
+{
+ char name[30];
+ struct date doj; // Date of Joining
+};
+
+int compare_dates(const void *a, const void *b);
+
+int main()
+{
+ struct employee emp[10];
+ int i;
+ // Temporary variables for input because we cannot take address of a bit-field
+ int d, m, y;
+
+ printf("Enter details for 10 employees:\n");
+ for (i = 0; i < 10; i++)
+ {
+ printf("\nEmployee %d Name: ", i + 1);
+ scanf("%s", emp[i].name);
+
+ printf("Date of Joining (dd mm yyyy): ");
+ scanf("%d %d %d", &d, &m, &y);
+
+ // Assign to bit-fields
+ emp[i].doj.day = d;
+ emp[i].doj.month = m;
+ emp[i].doj.year = y;
+ }
+
+ // Sort based on year using qsort
+ qsort(emp, 10, sizeof(struct employee), compare_dates);
+
+ printf("\n--- Employees Sorted by Joining Year ---\n");
+ for (i = 0; i < 10; i++)
+ {
+ printf("%-15s | DOJ: %02d-%02d-%d\n",
+ emp[i].name, emp[i].doj.day, emp[i].doj.month, emp[i].doj.year);
+ }
+
+ return 0;
+}
+
+int compare_dates(const void *a, const void *b)
+{
+ struct employee *e1 = (struct employee *)a;
+ struct employee *e2 = (struct employee *)b;
+
+ // Primary sort by Year
+ if (e1->doj.year != e2->doj.year)
+ return e1->doj.year - e2->doj.year;
+
+ // Secondary sort by Month
+ if (e1->doj.month != e2->doj.month)
+ return e1->doj.month - e2->doj.month;
+
+ // Tertiary sort by Day
+ return e1->doj.day - e2->doj.day;
+}</div>
+ </div>
+
+ <div class="file-item flex items-center justify-between px-3 py-2 hover:bg-white hover:shadow-sm rounded-lg transition-all group border border-transparent hover:border-slate-100 mb-1">
+ <div class="flex items-center gap-2.5 min-w-0 cursor-pointer flex-1" onclick="showCode('code-Semester_1-letusc-luc114-c', 'luc114.c', 'https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc114.c')">
+ <svg class="w-4 h-4 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
+ </svg>
+ <span class="text-sm text-slate-600 font-medium group-hover:text-blue-600 truncate">luc114.c</span>
+ </div>
+ <div class="flex items-center gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
+ <a href="https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc114.c" target="_blank" class="p-1.5 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded-md" title="View on GitHub">
+ <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-2.126 1.029-2.935-.103-.253-.446-1.372.097-2.897 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.525.202 2.644.1 2.897.64.809 1.026 1.841 1.026 2.935 0 3.847-2.337 4.687-4.565 4.935.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z" clip-rule="evenodd"></path></svg>
+ </a>
+ </div>
+ <!-- Embedded Code Storage -->
+ <div id="code-Semester_1-letusc-luc114-c" style="display:none;">/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Store insurance policy holder info (gender, minor/major, policy name, duration) using bit-fields.
+*/
+/* Let Us C, Chap- 22 (Miscellaneous Features), Qn No.: C(b) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+// Define structure with bit-fields
+struct policy_holder
+{
+ char policy_name[50];
+ unsigned int duration : 7; // 0-127 years is sufficient for policy duration
+ unsigned int gender : 1; // 0: Male, 1: Female (1 bit)
+ unsigned int status : 1; // 0: Minor, 1: Major (1 bit)
+};
+
+int main()
+{
+ struct policy_holder p;
+ int temp_gen, temp_stat, temp_dur;
+
+ printf("--- Enter Policy Holder Details ---\n");
+
+ printf("Policy Name: ");
+ scanf(" %[^\n]s", p.policy_name); // Reads string with spaces
+
+ printf("Duration (Years): ");
+ scanf("%d", &temp_dur);
+ p.duration = temp_dur;
+
+ printf("Gender (0 for Male, 1 for Female): ");
+ scanf("%d", &temp_gen);
+ p.gender = temp_gen;
+
+ printf("Status (0 for Minor, 1 for Major): ");
+ scanf("%d", &temp_stat);
+ p.status = temp_stat;
+
+ printf("\n--- Policy Information Stored ---\n");
+ printf("Policy: %s\n", p.policy_name);
+ printf("Duration: %u years\n", p.duration);
+
+ // Interpret bits for display
+ printf("Gender: %s\n", (p.gender == 1) ? "Female" : "Male");
+ printf("Status: %s\n", (p.status == 1) ? "Major" : "Minor");
+
+ printf("\nSize of structure: %zu bytes\n", sizeof(p));
+ // Note: Size will be policy_name size + padding + integer size containing the bits
+
+ return 0;
+}</div>
+ </div>
+
+ <div class="file-item flex items-center justify-between px-3 py-2 hover:bg-white hover:shadow-sm rounded-lg transition-all group border border-transparent hover:border-slate-100 mb-1">
+ <div class="flex items-center gap-2.5 min-w-0 cursor-pointer flex-1" onclick="showCode('code-Semester_1-letusc-luc115-c', 'luc115.c', 'https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc115.c')">
+ <svg class="w-4 h-4 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
+ </svg>
+ <span class="text-sm text-slate-600 font-medium group-hover:text-blue-600 truncate">luc115.c</span>
+ </div>
+ <div class="flex items-center gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
+ <a href="https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc115.c" target="_blank" class="p-1.5 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded-md" title="View on GitHub">
+ <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-2.126 1.029-2.935-.103-.253-.446-1.372.097-2.897 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.525.202 2.644.1 2.897.64.809 1.026 1.841 1.026 2.935 0 3.847-2.337 4.687-4.565 4.935.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z" clip-rule="evenodd"></path></svg>
+ </a>
+ </div>
+ <!-- Embedded Code Storage -->
+ <div id="code-Semester_1-letusc-luc115-c" style="display:none;">/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Obtain MD5 checksum of the following strings and check whether they are same:
+"Six slippery snails slid slowly seaward."
+"Six silppery snails slid slowly seaward."
+*/
+/* Let Us C, Chap- 23 (Security Programming), Qn No.: D(a) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdint.h>
+
+/* * Self-contained MD5 Implementation
+ * Based on the public domain reference implementation (RFC 1321) logic.
+ */
+
+// --- MD5 Implementation Start ---
+typedef struct {
+ uint64_t size; // Size of input in bytes
+ uint32_t buffer[4]; // Current accumulation of hash
+ uint8_t input[64]; // Input to be processed
+} MD5Context;
+
+#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
+#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
+#define H(x, y, z) ((x) ^ (y) ^ (z))
+#define I(x, y, z) ((y) ^ ((x) | (~z)))
+
+#define ROTL(x, s) (((x) << (s)) | ((x) >> (32 - (s))))
+
+#define STEP(f, a, b, c, d, x, t, s) \
+ (a) += f((b), (c), (d)) + (x) + (t); \
+ (a) = ROTL((a), (s)); \
+ (a) += (b);
+
+void md5Transform(uint32_t state[4], const uint8_t block[64]) {
+ uint32_t a = state[0], b = state[1], c = state[2], d = state[3], x[16];
+ int i, j;
+
+ // Decode block into x
+ for (i = 0, j = 0; j < 64; i++, j += 4)
+ x[i] = ((uint32_t)block[j]) | (((uint32_t)block[j + 1]) << 8) |
+ (((uint32_t)block[j + 2]) << 16) | (((uint32_t)block[j + 3]) << 24);
+
+ // Round 1
+ STEP(F, a, b, c, d, x[0], 0xd76aa478, 7);
+ STEP(F, d, a, b, c, x[1], 0xe8c7b756, 12);
+ STEP(F, c, d, a, b, x[2], 0x242070db, 17);
+ STEP(F, b, c, d, a, x[3], 0xc1bdceee, 22);
+ STEP(F, a, b, c, d, x[4], 0xf57c0faf, 7);
+ STEP(F, d, a, b, c, x[5], 0x4787c62a, 12);
+ STEP(F, c, d, a, b, x[6], 0xa8304613, 17);
+ STEP(F, b, c, d, a, x[7], 0xfd469501, 22);
+ STEP(F, a, b, c, d, x[8], 0x698098d8, 7);
+ STEP(F, d, a, b, c, x[9], 0x8b44f7af, 12);
+ STEP(F, c, d, a, b, x[10], 0xffff5bb1, 17);
+ STEP(F, b, c, d, a, x[11], 0x895cd7be, 22);
+ STEP(F, a, b, c, d, x[12], 0x6b901122, 7);
+ STEP(F, d, a, b, c, x[13], 0xfd987193, 12);
+ STEP(F, c, d, a, b, x[14], 0xa679438e, 17);
+ STEP(F, b, c, d, a, x[15], 0x49b40821, 22);
+
+ // Round 2
+ STEP(G, a, b, c, d, x[1], 0xf61e2562, 5);
+ STEP(G, d, a, b, c, x[6], 0xc040b340, 9);
+ STEP(G, c, d, a, b, x[11], 0x265e5a51, 14);
+ STEP(G, b, c, d, a, x[0], 0xe9b6c7aa, 20);
+ STEP(G, a, b, c, d, x[5], 0xd62f105d, 5);
+ STEP(G, d, a, b, c, x[10], 0x02441453, 9);
+ STEP(G, c, d, a, b, x[15], 0xd8a1e681, 14);
+ STEP(G, b, c, d, a, x[4], 0xe7d3fbc8, 20);
+ STEP(G, a, b, c, d, x[9], 0x21e1cde6, 5);
+ STEP(G, d, a, b, c, x[14], 0xc33707d6, 9);
+ STEP(G, c, d, a, b, x[3], 0xf4d50d87, 14);
+ STEP(G, b, c, d, a, x[8], 0x455a14ed, 20);
+ STEP(G, a, b, c, d, x[13], 0xa9e3e905, 5);
+ STEP(G, d, a, b, c, x[2], 0xfcefa3f8, 9);
+ STEP(G, c, d, a, b, x[7], 0x676f02d9, 14);
+ STEP(G, b, c, d, a, x[12], 0x8d2a4c8a, 20);
+
+ // Round 3
+ STEP(H, a, b, c, d, x[5], 0xfffa3942, 4);
+ STEP(H, d, a, b, c, x[8], 0x8771f681, 11);
+ STEP(H, c, d, a, b, x[11], 0x6d9d6122, 16);
+ STEP(H, b, c, d, a, x[14], 0xfde5380c, 23);
+ STEP(H, a, b, c, d, x[1], 0xa4beea44, 4);
+ STEP(H, d, a, b, c, x[4], 0x4bdecfa9, 11);
+ STEP(H, c, d, a, b, x[7], 0xf6bb4b60, 16);
+ STEP(H, b, c, d, a, x[10], 0xbebfbc70, 23);
+ STEP(H, a, b, c, d, x[13], 0x289b7ec6, 4);
+ STEP(H, d, a, b, c, x[0], 0xeaa127fa, 11);
+ STEP(H, c, d, a, b, x[3], 0xd4ef3085, 16);
+ STEP(H, b, c, d, a, x[6], 0x04881d05, 23);
+ STEP(H, a, b, c, d, x[9], 0xd9d4d039, 4);
+ STEP(H, d, a, b, c, x[12], 0xe6db99e5, 11);
+ STEP(H, c, d, a, b, x[15], 0x1fa27cf8, 16);
+ STEP(H, b, c, d, a, x[2], 0xc4ac5665, 23);
+
+ // Round 4
+ STEP(I, a, b, c, d, x[0], 0xf4292244, 6);
+ STEP(I, d, a, b, c, x[7], 0x432aff97, 10);
+ STEP(I, c, d, a, b, x[14], 0xab9423a7, 15);
+ STEP(I, b, c, d, a, x[5], 0xfc93a039, 21);
+ STEP(I, a, b, c, d, x[12], 0x655b59c3, 6);
+ STEP(I, d, a, b, c, x[3], 0x8f0ccc92, 10);
+ STEP(I, c, d, a, b, x[10], 0xffeff47d, 15);
+ STEP(I, b, c, d, a, x[1], 0x85845dd1, 21);
+ STEP(I, a, b, c, d, x[8], 0x6fa87e4f, 6);
+ STEP(I, d, a, b, c, x[15], 0xfe2ce6e0, 10);
+ STEP(I, c, d, a, b, x[6], 0xa3014314, 15);
+ STEP(I, b, c, d, a, x[13], 0x4e0811a1, 21);
+ STEP(I, a, b, c, d, x[4], 0xf7537e82, 6);
+ STEP(I, d, a, b, c, x[11], 0xbd3af235, 10);
+ STEP(I, c, d, a, b, x[2], 0x2ad7d2bb, 15);
+ STEP(I, b, c, d, a, x[9], 0xeb86d391, 21);
+
+ state[0] += a;
+ state[1] += b;
+ state[2] += c;
+ state[3] += d;
+}
+
+void md5Init(MD5Context *ctx) {
+ ctx->size = 0;
+ ctx->buffer[0] = 0x67452301;
+ ctx->buffer[1] = 0xefcdab89;
+ ctx->buffer[2] = 0x98badcfe;
+ ctx->buffer[3] = 0x10325476;
+}
+
+void md5Update(MD5Context *ctx, const uint8_t *input, size_t inputLen) {
+ size_t i, index, partLen;
+ index = (size_t)((ctx->size >> 3) & 0x3f);
+ ctx->size += (uint64_t)inputLen * 8;
+ partLen = 64 - index;
+
+ if (inputLen >= partLen) {
+ memcpy(&ctx->input[index], input, partLen);
+ md5Transform(ctx->buffer, ctx->input);
+ for (i = partLen; i + 63 < inputLen; i += 64)
+ md5Transform(ctx->buffer, &input[i]);
+ index = 0;
+ } else {
+ i = 0;
+ }
+ memcpy(&ctx->input[index], &input[i], inputLen - i);
+}
+
+void md5Final(uint8_t digest[16], MD5Context *ctx) {
+ uint8_t bits[8];
+ size_t index, padLen;
+ static const uint8_t PADDING[64] = {0x80}; // Remaining zeros implicit
+
+ // Save number of bits
+ for (int i = 0; i < 8; i++)
+ bits[i] = (uint8_t)((ctx->size >> (i * 8)) & 0xff);
+
+ index = (size_t)((ctx->size >> 3) & 0x3f);
+ padLen = (index < 56) ? (56 - index) : (120 - index);
+ md5Update(ctx, PADDING, padLen);
+ md5Update(ctx, bits, 8);
+
+ // Encode state into digest
+ for (int i = 0; i < 16; i++)
+ digest[i] = (uint8_t)((ctx->buffer[i >> 2] >> ((i & 3) * 8)) & 0xff);
+}
+// --- MD5 Implementation End ---
+
+void print_hash(uint8_t *digest) {
+ for (int i = 0; i < 16; i++) printf("%02x", digest[i]);
+ printf("\n");
+}
+
+int main() {
+ char str1[] = "Six slippery snails slid slowly seaward.";
+ char str2[] = "Six silppery snails slid slowly seaward."; // Typo 'silppery'
+
+ uint8_t hash1[16], hash2[16];
+ MD5Context ctx;
+
+ printf("String 1: %s\n", str1);
+ md5Init(&ctx);
+ md5Update(&ctx, (uint8_t*)str1, strlen(str1));
+ md5Final(hash1, &ctx);
+ printf("MD5: ");
+ print_hash(hash1);
+
+ printf("\nString 2: %s\n", str2);
+ md5Init(&ctx);
+ md5Update(&ctx, (uint8_t*)str2, strlen(str2));
+ md5Final(hash2, &ctx);
+ printf("MD5: ");
+ print_hash(hash2);
+
+ // Compare
+ int same = 1;
+ for(int i=0; i<16; i++) if(hash1[i] != hash2[i]) same = 0;
+
+ printf("\nConclusion: The MD5 checksums are %s.\n", same ? "IDENTICAL" : "DIFFERENT");
+ if (!same) printf("(Even a small change in input creates a completely different hash)\n");
+
+ return 0;
+}</div>
+ </div>
+
+ <div class="file-item flex items-center justify-between px-3 py-2 hover:bg-white hover:shadow-sm rounded-lg transition-all group border border-transparent hover:border-slate-100 mb-1">
+ <div class="flex items-center gap-2.5 min-w-0 cursor-pointer flex-1" onclick="showCode('code-Semester_1-letusc-luc116-c', 'luc116.c', 'https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc116.c')">
+ <svg class="w-4 h-4 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
+ </svg>
+ <span class="text-sm text-slate-600 font-medium group-hover:text-blue-600 truncate">luc116.c</span>
+ </div>
+ <div class="flex items-center gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
+ <a href="https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc116.c" target="_blank" class="p-1.5 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded-md" title="View on GitHub">
+ <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-2.126 1.029-2.935-.103-.253-.446-1.372.097-2.897 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.525.202 2.644.1 2.897.64.809 1.026 1.841 1.026 2.935 0 3.847-2.337 4.687-4.565 4.935.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z" clip-rule="evenodd"></path></svg>
+ </a>
+ </div>
+ <!-- Embedded Code Storage -->
+ <div id="code-Semester_1-letusc-luc116-c" style="display:none;">/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Compile any C program into a .EXE or a .out file. Obtain SHA256 checksum of the file.
+*/
+/* Let Us C, Chap- 23 (Security Programming), Qn No.: D(b) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdint.h>
+
+/* * Self-contained SHA-256 Implementation
+ * Based on FIPS 180-2 reference logic.
+ */
+
+// --- SHA256 Implementation Start ---
+typedef struct {
+ uint8_t data[64];
+ uint32_t datalen;
+ uint64_t bitlen;
+ uint32_t state[8];
+} SHA256_CTX;
+
+#define ROTRIGHT(a,b) (((a) >> (b)) | ((a) << (32-(b))))
+#define CH(x,y,z) (((x) & (y)) ^ (~(x) & (z)))
+#define MAJ(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)))
+#define EP0(x) (ROTRIGHT(x,2) ^ ROTRIGHT(x,13) ^ ROTRIGHT(x,22))
+#define EP1(x) (ROTRIGHT(x,6) ^ ROTRIGHT(x,11) ^ ROTRIGHT(x,25))
+#define SIG0(x) (ROTRIGHT(x,7) ^ ROTRIGHT(x,18) ^ ((x) >> 3))
+#define SIG1(x) (ROTRIGHT(x,17) ^ ROTRIGHT(x,19) ^ ((x) >> 10))
+
+static const uint32_t K[64] = {
+ 0x428a2f98,0x71374491,0xb5c0fbcf,0xe9b5dba5,0x3956c25b,0x59f111f1,0x923f82a4,0xab1c5ed5,
+ 0xd807aa98,0x12835b01,0x243185be,0x550c7dc3,0x72be5d74,0x80deb1fe,0x9bdc06a7,0xc19bf174,
+ 0xe49b69c1,0xefbe4786,0x0fc19dc6,0x240ca1cc,0x2de92c6f,0x4a7484aa,0x5cb0a9dc,0x76f988da,
+ 0x983e5152,0xa831c66d,0xb00327c8,0xbf597fc7,0xc6e00bf3,0xd5a79147,0x06ca6351,0x14292967,
+ 0x27b70a85,0x2e1b2138,0x4d2c6dfc,0x53380d13,0x650a7354,0x766a0abb,0x81c2c92e,0x92722c85,
+ 0xa2bfe8a1,0xa81a664b,0xc24b8b70,0xc76c51a3,0xd192e819,0xd6990624,0xf40e3585,0x106aa070,
+ 0x19a4c116,0x1e376c08,0x2748774c,0x34b0bcb5,0x391c0cb3,0x4ed8aa4a,0x5b9cca4f,0x682e6ff3,
+ 0x748f82ee,0x78a5636f,0x84c87814,0x8cc70208,0x90befffa,0xa4506ceb,0xbef9a3f7,0xc67178f2
+};
+
+void sha256_transform(SHA256_CTX *ctx, const uint8_t data[]) {
+ uint32_t a, b, c, d, e, f, g, h, i, j, t1, t2, m[64];
+
+ for (i = 0, j = 0; i < 16; ++i, j += 4)
+ m[i] = (data[j] << 24) | (data[j + 1] << 16) | (data[j + 2] << 8) | (data[j + 3]);
+ for (; i < 64; ++i)
+ m[i] = SIG1(m[i - 2]) + m[i - 7] + SIG0(m[i - 15]) + m[i - 16];
+
+ a = ctx->state[0]; b = ctx->state[1]; c = ctx->state[2]; d = ctx->state[3];
+ e = ctx->state[4]; f = ctx->state[5]; g = ctx->state[6]; h = ctx->state[7];
+
+ for (i = 0; i < 64; ++i) {
+ t1 = h + EP1(e) + CH(e, f, g) + K[i] + m[i];
+ t2 = EP0(a) + MAJ(a, b, c);
+ h = g; g = f; f = e; e = d + t1;
+ d = c; c = b; b = a; a = t1 + t2;
+ }
+
+ ctx->state[0] += a; ctx->state[1] += b; ctx->state[2] += c; ctx->state[3] += d;
+ ctx->state[4] += e; ctx->state[5] += f; ctx->state[6] += g; ctx->state[7] += h;
+}
+
+void sha256_init(SHA256_CTX *ctx) {
+ ctx->datalen = 0;
+ ctx->bitlen = 0;
+ ctx->state[0] = 0x6a09e667; ctx->state[1] = 0xbb67ae85;
+ ctx->state[2] = 0x3c6ef372; ctx->state[3] = 0xa54ff53a;
+ ctx->state[4] = 0x510e527f; ctx->state[5] = 0x9b05688c;
+ ctx->state[6] = 0x1f83d9ab; ctx->state[7] = 0x5be0cd19;
+}
+
+void sha256_update(SHA256_CTX *ctx, const uint8_t data[], size_t len) {
+ for (size_t i = 0; i < len; ++i) {
+ ctx->data[ctx->datalen] = data[i];
+ ctx->datalen++;
+ if (ctx->datalen == 64) {
+ sha256_transform(ctx, ctx->data);
+ ctx->bitlen += 512;
+ ctx->datalen = 0;
+ }
+ }
+}
+
+void sha256_final(SHA256_CTX *ctx, uint8_t hash[]) {
+ uint32_t i = ctx->datalen;
+ if (ctx->datalen < 56) {
+ ctx->data[i++] = 0x80;
+ while (i < 56) ctx->data[i++] = 0x00;
+ } else {
+ ctx->data[i++] = 0x80;
+ while (i < 64) ctx->data[i++] = 0x00;
+ sha256_transform(ctx, ctx->data);
+ memset(ctx->data, 0, 56);
+ }
+
+ ctx->bitlen += ctx->datalen * 8;
+ ctx->data[63] = ctx->bitlen;
+ ctx->data[62] = ctx->bitlen >> 8;
+ ctx->data[61] = ctx->bitlen >> 16;
+ ctx->data[60] = ctx->bitlen >> 24;
+ ctx->data[59] = ctx->bitlen >> 32;
+ ctx->data[58] = ctx->bitlen >> 40;
+ ctx->data[57] = ctx->bitlen >> 48;
+ ctx->data[56] = ctx->bitlen >> 56;
+ sha256_transform(ctx, ctx->data);
+
+ for (i = 0; i < 4; ++i) {
+ hash[i] = (ctx->state[0] >> (24 - i * 8)) & 0x000000ff;
+ hash[i + 4] = (ctx->state[1] >> (24 - i * 8)) & 0x000000ff;
+ hash[i + 8] = (ctx->state[2] >> (24 - i * 8)) & 0x000000ff;
+ hash[i + 12] = (ctx->state[3] >> (24 - i * 8)) & 0x000000ff;
+ hash[i + 16] = (ctx->state[4] >> (24 - i * 8)) & 0x000000ff;
+ hash[i + 20] = (ctx->state[5] >> (24 - i * 8)) & 0x000000ff;
+ hash[i + 24] = (ctx->state[6] >> (24 - i * 8)) & 0x000000ff;
+ hash[i + 28] = (ctx->state[7] >> (24 - i * 8)) & 0x000000ff;
+ }
+}
+// --- SHA256 Implementation End ---
+
+int main(int argc, char *argv[]) {
+ FILE *fp;
+ char filename[100];
+ uint8_t buffer[1024];
+ size_t bytesRead;
+ SHA256_CTX ctx;
+ uint8_t hash[32];
+ int i;
+
+ // Get filename
+ if (argc < 2) {
+ printf("Enter filename to checksum (e.g., this_program.exe): ");
+ scanf("%s", filename);
+ } else {
+ strcpy(filename, argv[1]);
+ }
+
+ fp = fopen(filename, "rb"); // Open in binary mode
+ if (fp == NULL) {
+ printf("Error: Could not open file '%s'\n", filename);
+ return 1;
+ }
+
+ sha256_init(&ctx);
+
+ while ((bytesRead = fread(buffer, 1, sizeof(buffer), fp)) > 0) {
+ sha256_update(&ctx, buffer, bytesRead);
+ }
+
+ sha256_final(&ctx, hash);
+ fclose(fp);
+
+ printf("SHA256 Checksum of '%s':\n", filename);
+ for (i = 0; i < 32; i++) {
+ printf("%02x", hash[i]);
+ }
+ printf("\n");
+
+ return 0;
+}</div>
+ </div>
+
+ <div class="file-item flex items-center justify-between px-3 py-2 hover:bg-white hover:shadow-sm rounded-lg transition-all group border border-transparent hover:border-slate-100 mb-1">
+ <div class="flex items-center gap-2.5 min-w-0 cursor-pointer flex-1" onclick="showCode('code-Semester_1-letusc-luc117-c', 'luc117.c', 'https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc117.c')">
+ <svg class="w-4 h-4 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
+ </svg>
+ <span class="text-sm text-slate-600 font-medium group-hover:text-blue-600 truncate">luc117.c</span>
+ </div>
+ <div class="flex items-center gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
+ <a href="https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc117.c" target="_blank" class="p-1.5 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded-md" title="View on GitHub">
+ <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-2.126 1.029-2.935-.103-.253-.446-1.372.097-2.897 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.525.202 2.644.1 2.897.64.809 1.026 1.841 1.026 2.935 0 3.847-2.337 4.687-4.565 4.935.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z" clip-rule="evenodd"></path></svg>
+ </a>
+ </div>
+ <!-- Embedded Code Storage -->
+ <div id="code-Semester_1-letusc-luc117-c" style="display:none;">/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Write a program to convert a given text into an audio file using OpenAI Audio API (TTS).
+*/
+/* Let Us C, Chap- 24 (Interaction with ChatGPT through C), Qn No.: B(a) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+/* NOTE: These programs require the 'libcurl' library to compile.
+ Command: gcc luc117.c -o output -lcurl */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <curl/curl.h>
+
+/* Pre-requisites:
+ 1. Install libcurl development package.
+ 2. Get OpenAI API Key.
+*/
+
+#define API_KEY "YOUR_OPENAI_API_KEY_HERE"
+
+size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) {
+ size_t written = fwrite(ptr, size, nmemb, stream);
+ return written;
+}
+
+int main(void) {
+ CURL *curl;
+ CURLcode res;
+ FILE *fp;
+
+ // JSON Payload construction
+ const char *url = "https://api.openai.com/v1/audio/speech";
+ const char *data = "{"
+ "\"model\": \"tts-1\","
+ "\"input\": \"Hello! This is a C program talking to you.\","
+ "\"voice\": \"alloy\""
+ "}";
+
+ struct curl_slist *headers = NULL;
+ char auth_header[100];
+ sprintf(auth_header, "Authorization: Bearer %s", API_KEY);
+
+ curl_global_init(CURL_GLOBAL_ALL);
+ curl = curl_easy_init();
+
+ if(curl) {
+ // Set Headers
+ headers = curl_slist_append(headers, "Content-Type: application/json");
+ headers = curl_slist_append(headers, auth_header);
+
+ // Open file to save audio
+ fp = fopen("output_audio.mp3", "wb");
+ if(!fp) {
+ printf("Error opening file for writing.\n");
+ return 1;
+ }
+
+ // Configure CURL
+ curl_easy_setopt(curl, CURLOPT_URL, url);
+ curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
+ curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
+ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
+ curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
+
+ // Perform Request
+ printf("Sending request to OpenAI TTS API...\n");
+ res = curl_easy_perform(curl);
+
+ if(res != CURLE_OK)
+ fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
+ else
+ printf("Audio saved to 'output_audio.mp3' successfully.\n");
+
+ // Cleanup
+ fclose(fp);
+ curl_slist_free_all(headers);
+ curl_easy_cleanup(curl);
+ }
+
+ curl_global_cleanup();
+ return 0;
+}</div>
+ </div>
+
+ <div class="file-item flex items-center justify-between px-3 py-2 hover:bg-white hover:shadow-sm rounded-lg transition-all group border border-transparent hover:border-slate-100 mb-1">
+ <div class="flex items-center gap-2.5 min-w-0 cursor-pointer flex-1" onclick="showCode('code-Semester_1-letusc-luc118-c', 'luc118.c', 'https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc118.c')">
+ <svg class="w-4 h-4 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
+ </svg>
+ <span class="text-sm text-slate-600 font-medium group-hover:text-blue-600 truncate">luc118.c</span>
+ </div>
+ <div class="flex items-center gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
+ <a href="https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc118.c" target="_blank" class="p-1.5 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded-md" title="View on GitHub">
+ <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-2.126 1.029-2.935-.103-.253-.446-1.372.097-2.897 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.525.202 2.644.1 2.897.64.809 1.026 1.841 1.026 2.935 0 3.847-2.337 4.687-4.565 4.935.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z" clip-rule="evenodd"></path></svg>
+ </a>
+ </div>
+ <!-- Embedded Code Storage -->
+ <div id="code-Semester_1-letusc-luc118-c" style="display:none;">/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Write a program to generate 4 images of birds flying in the sky with a computer's mouse in their beak using OpenAI Image API.
+*/
+/* Let Us C, Chap- 24 (Interaction with ChatGPT through C), Qn No.: B(b) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+/* NOTE: These programs require the 'libcurl' library to compile.
+ Command: gcc luc118.c -o output -lcurl */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <curl/curl.h>
+
+/* Pre-requisites:
+ 1. Install libcurl.
+ 2. Get OpenAI API Key.
+*/
+
+#define API_KEY "YOUR_OPENAI_API_KEY_HERE"
+
+int main(void) {
+ CURL *curl;
+ CURLcode res;
+
+ const char *url = "https://api.openai.com/v1/images/generations";
+
+ // JSON Payload: 4 images, 1024x1024
+ const char *data = "{"
+ "\"prompt\": \"Birds flying in the sky with a computer mouse in their beak\","
+ "\"n\": 4,"
+ "\"size\": \"1024x1024\""
+ "}";
+
+ struct curl_slist *headers = NULL;
+ char auth_header[100];
+ sprintf(auth_header, "Authorization: Bearer %s", API_KEY);
+
+ curl = curl_easy_init();
+ if(curl) {
+ headers = curl_slist_append(headers, "Content-Type: application/json");
+ headers = curl_slist_append(headers, auth_header);
+
+ curl_easy_setopt(curl, CURLOPT_URL, url);
+ curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
+ curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
+
+ // For simplicity, we print the JSON response to stdout.
+ // The response will contain URLs to the generated images.
+ printf("Sending request to OpenAI Image API...\n\n");
+ res = curl_easy_perform(curl);
+
+ if(res != CURLE_OK)
+ fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
+
+ printf("\n\nCheck the JSON output above for 'url' fields to view images.\n");
+
+ curl_slist_free_all(headers);
+ curl_easy_cleanup(curl);
+ }
+ return 0;
+}</div>
+ </div>
+
+ <div class="file-item flex items-center justify-between px-3 py-2 hover:bg-white hover:shadow-sm rounded-lg transition-all group border border-transparent hover:border-slate-100 mb-1">
+ <div class="flex items-center gap-2.5 min-w-0 cursor-pointer flex-1" onclick="showCode('code-Semester_1-letusc-luc119-c', 'luc119.c', 'https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc119.c')">
+ <svg class="w-4 h-4 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
+ </svg>
+ <span class="text-sm text-slate-600 font-medium group-hover:text-blue-600 truncate">luc119.c</span>
+ </div>
+ <div class="flex items-center gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
+ <a href="https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/luc119.c" target="_blank" class="p-1.5 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded-md" title="View on GitHub">
+ <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-2.126 1.029-2.935-.103-.253-.446-1.372.097-2.897 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.525.202 2.644.1 2.897.64.809 1.026 1.841 1.026 2.935 0 3.847-2.337 4.687-4.565 4.935.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z" clip-rule="evenodd"></path></svg>
+ </a>
+ </div>
+ <!-- Embedded Code Storage -->
+ <div id="code-Semester_1-letusc-luc119-c" style="display:none;">/*
+ * Author : Amit Dutta <amitdutta4255@gmail.com>
+ * Date : 08 Feb 2026
+ * Repo : https://github.com/notamitgamer/bsc
+ * License : MIT License (See the LICENSE file for details)
+ * Copyright (c) 2026 Amit Dutta
+ */
+
+/* Write a program to analyse a given sentence to detect the mood of the sentence using OpenAI Chat Completion API.
+*/
+/* Let Us C, Chap- 24 (Interaction with ChatGPT through C), Qn No.: B(c) */
+
+/* This file is auto-generated by a bot. */
+/* This code is not compiled; it is for reference only. */
+
+/* NOTE: These programs require the 'libcurl' library to compile.
+ Command: gcc luc119.c -o output -lcurl */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <curl/curl.h>
+
+/* Pre-requisites:
+ 1. Install libcurl.
+ 2. Get OpenAI API Key.
+*/
+
+#define API_KEY "YOUR_OPENAI_API_KEY_HERE"
+
+int main(void) {
+ CURL *curl;
+ CURLcode res;
+
+ const char *url = "https://api.openai.com/v1/chat/completions";
+
+ /* We construct the JSON payload manually.
+ System prompt instructs the model to detect mood.
+ User prompt is the sentence to analyze.
+ */
+ const char *data = "{"
+ "\"model\": \"gpt-3.5-turbo\","
+ "\"messages\": ["
+ " {\"role\": \"system\", \"content\": \"You are a helpful assistant. Analyze the mood of the user input sentence. Return only the mood keywords (e.g., admiration, appreciation, anger, joy).\"},"
+ " {\"role\": \"user\", \"content\": \"I am so impressed by your performance\"}"
+ "]"
+ "}";
+
+ struct curl_slist *headers = NULL;
+ char auth_header[100];
+ sprintf(auth_header, "Authorization: Bearer %s", API_KEY);
+
+ curl = curl_easy_init();
+ if(curl) {
+ headers = curl_slist_append(headers, "Content-Type: application/json");
+ headers = curl_slist_append(headers, auth_header);
+
+ curl_easy_setopt(curl, CURLOPT_URL, url);
+ curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
+ curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
+
+ printf("Analyzing sentence: 'I am so impressed by your performance'\n");
+ printf("Waiting for OpenAI response...\n\n");
+
+ // The response will be printed to standard output
+ res = curl_easy_perform(curl);
+
+ if(res != CURLE_OK)
+ fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
+
+ printf("\n\n(Parse the JSON above to extract the 'content' field)\n");
+
+ curl_slist_free_all(headers);
+ curl_easy_cleanup(curl);
+ }
+ return 0;
+}</div>
+ </div>
+
+ <div class="file-item flex items-center justify-between px-3 py-2 hover:bg-white hover:shadow-sm rounded-lg transition-all group border border-transparent hover:border-slate-100 mb-1">
<div class="flex items-center gap-2.5 min-w-0 cursor-pointer flex-1" onclick="showCode('code-Semester_1-letusc-lucproblem001-c', 'lucproblem001.c', 'https://github.com/notamitgamer/bsc/blob/main/Semester_1/letusc/lucproblem001.c')">
<svg class="w-4 h-4 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />