bsc

Comprehensive codebase and cou...
Log | Files | Refs | README | LICENSE

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:
MREADME.md | 1+
ASemester_1/letusc/luc078.c | 86+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ASemester_1/letusc/luc079.c | 104+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ASemester_1/letusc/luc080.c | 65+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ASemester_1/letusc/luc081.c | 64++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ASemester_1/letusc/luc082.c | 70++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ASemester_1/letusc/luc083.c | 139+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ASemester_1/letusc/luc084.c | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
ASemester_1/letusc/luc085.c | 83+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ASemester_1/letusc/luc086.c | 70++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ASemester_1/letusc/luc087.c | 89+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ASemester_1/letusc/luc088.c | 76++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ASemester_1/letusc/luc089.c | 119+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ASemester_1/letusc/luc090.c | 90+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ASemester_1/letusc/luc091.c | 70++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ASemester_1/letusc/luc092.c | 63+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ASemester_1/letusc/luc093.c | 132+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ASemester_1/letusc/luc094.c | 67+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ASemester_1/letusc/luc095.c | 50++++++++++++++++++++++++++++++++++++++++++++++++++
ASemester_1/letusc/luc096.c | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ASemester_1/letusc/luc097.c | 103+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ASemester_1/letusc/luc098.c | 81+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ASemester_1/letusc/luc099.c | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
ASemester_1/letusc/luc100.c | 49+++++++++++++++++++++++++++++++++++++++++++++++++
ASemester_1/letusc/luc101.c | 57+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ASemester_1/letusc/luc102.c | 36++++++++++++++++++++++++++++++++++++
ASemester_1/letusc/luc103.c | 37+++++++++++++++++++++++++++++++++++++
ASemester_1/letusc/luc104.c | 44++++++++++++++++++++++++++++++++++++++++++++
ASemester_1/letusc/luc105.c | 53+++++++++++++++++++++++++++++++++++++++++++++++++++++
ASemester_1/letusc/luc106.c | 39+++++++++++++++++++++++++++++++++++++++
ASemester_1/letusc/luc107.c | 38++++++++++++++++++++++++++++++++++++++
ASemester_1/letusc/luc108.c | 38++++++++++++++++++++++++++++++++++++++
ASemester_1/letusc/luc109.c | 38++++++++++++++++++++++++++++++++++++++
ASemester_1/letusc/luc110.c | 44++++++++++++++++++++++++++++++++++++++++++++
ASemester_1/letusc/luc111.c | 43+++++++++++++++++++++++++++++++++++++++++++
ASemester_1/letusc/luc112.c | 53+++++++++++++++++++++++++++++++++++++++++++++++++++++
ASemester_1/letusc/luc113.c | 88+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ASemester_1/letusc/luc114.c | 65+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ASemester_1/letusc/luc115.c | 215+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ASemester_1/letusc/luc116.c | 172+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ASemester_1/letusc/luc117.c | 94+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ASemester_1/letusc/luc118.c | 73+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ASemester_1/letusc/luc119.c | 79+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mdocs/index.html | 3731+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
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", &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; +}+ \ 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 &lt;amitdutta4255@gmail.com&gt; + * 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 &#x27;student&#x27; (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 &lt;stdio.h&gt; +#include &lt;string.h&gt; +#include &lt;stdlib.h&gt; + +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, &quot;Amit&quot;, &quot;CS&quot;, &quot;B.Sc&quot;, 2024}, + {102, &quot;Rahul&quot;, &quot;Physics&quot;, &quot;B.Sc&quot;, 2024}, + {103, &quot;Sneha&quot;, &quot;CS&quot;, &quot;M.Sc&quot;, 2023}, + {104, &quot;Priya&quot;, &quot;Maths&quot;, &quot;B.Sc&quot;, 2025}, + {105, &quot;Rohan&quot;, &quot;CS&quot;, &quot;B.Sc&quot;, 2024} + }; + int n = 5; // Using 5 sample records + int year, roll; + + printf(&quot;Enter year to list students: &quot;); + scanf(&quot;%d&quot;, &amp;year); + print_by_year(data, n, year); + + printf(&quot;\nEnter roll number to find student: &quot;); + scanf(&quot;%d&quot;, &amp;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(&quot;Students joining in %d:\n&quot;, year); + for (i = 0; i &lt; n; i++) + { + if (s[i].year == year) + { + printf(&quot;- %s\n&quot;, s[i].name); + found = 1; + } + } + if (!found) printf(&quot;No students found for this year.\n&quot;); +} + +void print_by_roll(struct student *s, int n, int roll) +{ + int i; + for (i = 0; i &lt; n; i++) + { + if (s[i].roll == roll) + { + printf(&quot;\n--- Student Details ---\n&quot;); + printf(&quot;Roll: %d\nName: %s\nDept: %s\nCourse: %s\nYear: %d\n&quot;, + s[i].roll, s[i].name, s[i].dept, s[i].course, s[i].year); + return; + } + } + printf(&quot;Student with Roll %d not found.\n&quot;, 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 &lt;amitdutta4255@gmail.com&gt; + * 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 &lt;stdio.h&gt; +#include &lt;string.h&gt; +#include &lt;stdlib.h&gt; + +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, &quot;Alice&quot;, 5000.0}, + {1002, &quot;Bob&quot;, 500.0}, + {1003, &quot;Charlie&quot;, 1200.0}, + {1004, &quot;David&quot;, 800.0}, + {1005, &quot;Eve&quot;, 2000.0} + }; + int n = 5; + int acc, code; + float amt; + + // Task 1: Low Balance + printf(&quot;--- Customers with Balance &lt; Rs. 1000 ---\n&quot;); + print_low_balance(bank, n); + + // Task 2: Transaction + printf(&quot;\n--- Transaction Menu ---\n&quot;); + printf(&quot;Enter Account No, Amount, Code (1=Deposit, 0=Withdraw): &quot;); + scanf(&quot;%d %f %d&quot;, &amp;acc, &amp;amt, &amp;code); + + transaction(bank, n, acc, amt, code); + + return 0; +} + +void print_low_balance(struct customer *c, int n) +{ + int i; + for (i = 0; i &lt; n; i++) + { + if (c[i].balance &lt; 1000) + { + printf(&quot;Acc: %d, Name: %s, Bal: %.2f\n&quot;, 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 &lt; n; i++) + { + if (c[i].acc_no == acc) + { + found = 1; + if (code == 1) // Deposit + { + c[i].balance += amount; + printf(&quot;Deposit successful. New Balance: %.2f\n&quot;, c[i].balance); + } + else if (code == 0) // Withdraw + { + if (c[i].balance - amount &lt; 1000) + { + printf(&quot;The balance is insufficient for the specified withdrawal (Must maintain min 1000).\n&quot;); + } + else + { + c[i].balance -= amount; + printf(&quot;Withdrawal successful. New Balance: %.2f\n&quot;, c[i].balance); + } + } + else + { + printf(&quot;Invalid transaction code.\n&quot;); + } + break; + } + } + if (!found) printf(&quot;Account number not found.\n&quot;); +}</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 &lt;amitdutta4255@gmail.com&gt; + * 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 &lt;stdio.h&gt; +#include &lt;string.h&gt; +#include &lt;stdlib.h&gt; + +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[] = { + {&quot;AA0&quot;, 2020, &quot;Steel&quot;, 50}, + {&quot;BB2&quot;, 2021, &quot;Aluminum&quot;, 20}, + {&quot;BB5&quot;, 2022, &quot;Carbon&quot;, 10}, + {&quot;CC1&quot;, 2021, &quot;Steel&quot;, 100}, + {&quot;CC7&quot;, 2023, &quot;Titanium&quot;, 5}, + {&quot;FF9&quot;, 2024, &quot;Iron&quot;, 60} + }; + int n = 6; + + printf(&quot;--- Parts with Serial Numbers between BB1 and CC6 ---\n&quot;); + retrieve_parts(inventory, n); + + return 0; +} + +void retrieve_parts(struct part *p, int n) +{ + int i; + // We compare strings lexicographically + char start[] = &quot;BB1&quot;; + char end[] = &quot;CC6&quot;; + + for (i = 0; i &lt; n; i++) + { + if (strcmp(p[i].serial, start) &gt;= 0 &amp;&amp; strcmp(p[i].serial, end) &lt;= 0) + { + printf(&quot;Serial: %s | Year: %d | Mat: %s | Qty: %d\n&quot;, + 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 &lt;amitdutta4255@gmail.com&gt; + * 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 &lt;stdio.h&gt; +#include &lt;string.h&gt; +#include &lt;stdlib.h&gt; + +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-&gt;avg_runs &gt; c2-&gt;avg_runs) return 1; + else if (c1-&gt;avg_runs &lt; c2-&gt;avg_runs) return -1; + else return 0; +} + +int main() +{ + // Initializing fewer than 20 for demonstration, but logic applies to 20 + struct cricketer team[5] = { + {&quot;Kohli&quot;, 34, 110, 53.4}, + {&quot;Smith&quot;, 33, 95, 59.8}, + {&quot;Root&quot;, 32, 120, 50.1}, + {&quot;Sharma&quot;, 35, 80, 45.5}, + {&quot;Williamson&quot;, 32, 90, 54.0} + }; + int n = 5, i; + + printf(&quot;Before Sorting:\n&quot;); + for (i = 0; i &lt; n; i++) + printf(&quot;%s: %.2f\n&quot;, team[i].name, team[i].avg_runs); + + qsort(team, n, sizeof(struct cricketer), compare); + + printf(&quot;\nAfter Sorting (Ascending Avg Runs):\n&quot;); + for (i = 0; i &lt; n; i++) + printf(&quot;%s: %.2f\n&quot;, 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 &lt;amitdutta4255@gmail.com&gt; + * 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 &#x27;employee&#x27; (Code, Name, Date of Joining). Display names of employees with tenure &gt;= 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 &lt;stdio.h&gt; +#include &lt;string.h&gt; +#include &lt;stdlib.h&gt; + +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, &quot;Amit&quot;, {12, 1, 2020}}, + {102, &quot;Sumit&quot;, {15, 8, 2023}}, + {103, &quot;Rina&quot;, {1, 1, 2018}}, + {104, &quot;Tina&quot;, {20, 5, 2022}}, + {105, &quot;Mina&quot;, {10, 12, 2025}} + }; + int n = 5, i; + struct date current; + + printf(&quot;Enter current date (dd mm yyyy): &quot;); + scanf(&quot;%d %d %d&quot;, &amp;current.day, &amp;current.month, &amp;current.year); + + printf(&quot;\nEmployees with tenure &gt;= 3 years:\n&quot;); + for (i = 0; i &lt; n; i++) + { + int years = current.year - emp[i].doj.year; + + // Adjust for month/day + if (current.month &lt; emp[i].doj.month || + (current.month == emp[i].doj.month &amp;&amp; current.day &lt; emp[i].doj.day)) + { + years--; + } + + if (years &gt;= 3) + { + printf(&quot;%s (Tenure: %d years)\n&quot;, 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 &lt;amitdutta4255@gmail.com&gt; + * 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 &lt;stdio.h&gt; +#include &lt;string.h&gt; +#include &lt;stdlib.h&gt; + +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(&quot;\n--- Library Menu ---\n&quot;); + printf(&quot;1. Add Book Info\n&quot;); + printf(&quot;2. Display Book Info\n&quot;); + printf(&quot;3. List books of given author\n&quot;); + printf(&quot;4. List title of specified accession number\n&quot;); + printf(&quot;5. List count of books\n&quot;); + printf(&quot;6. List books in order of accession number\n&quot;); + printf(&quot;7. Exit\n&quot;); + printf(&quot;Enter choice: &quot;); + scanf(&quot;%d&quot;, &amp;choice); + + switch (choice) + { + case 1: add_book(books, &amp;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(&quot;Total books in library: %d\n&quot;, count); break; + case 6: sort_by_acc(books, count); display_books(books, count); break; + case 7: exit(0); + default: printf(&quot;Invalid choice!\n&quot;); + } + } + return 0; +} + +void add_book(struct library *lib, int *count) +{ + printf(&quot;Enter Accession No, Title, Author, Price, Issued(1/0):\n&quot;); + scanf(&quot;%d&quot;, &amp;lib[*count].acc_no); + scanf(&quot;%s&quot;, lib[*count].title); // Using %s for simplicity (no spaces) + scanf(&quot;%s&quot;, lib[*count].author); + scanf(&quot;%f&quot;, &amp;lib[*count].price); + scanf(&quot;%d&quot;, &amp;lib[*count].is_issued); + (*count)++; +} + +void display_books(struct library *lib, int count) +{ + int i; + for (i = 0; i &lt; count; i++) + printf(&quot;%d: %s by %s ($%.2f) Issued: %d\n&quot;, + 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(&quot;Enter author name: &quot;); + scanf(&quot;%s&quot;, author); + for (i = 0; i &lt; count; i++) + { + if (strcmp(lib[i].author, author) == 0) + { + printf(&quot;%s\n&quot;, lib[i].title); + found = 1; + } + } + if (!found) printf(&quot;No books found.\n&quot;); +} + +void list_title_by_acc(struct library *lib, int count) +{ + int acc, i; + printf(&quot;Enter Accession No: &quot;); + scanf(&quot;%d&quot;, &amp;acc); + for (i = 0; i &lt; count; i++) + { + if (lib[i].acc_no == acc) + { + printf(&quot;Title: %s\n&quot;, lib[i].title); + return; + } + } + printf(&quot;Book not found.\n&quot;); +} + +void sort_by_acc(struct library *lib, int count) +{ + struct library temp; + int i, j; + for (i = 0; i &lt; count - 1; i++) + { + for (j = 0; j &lt; count - i - 1; j++) + { + if (lib[j].acc_no &gt; 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 &lt;amitdutta4255@gmail.com&gt; + * 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 &lt;stdio.h&gt; +#include &lt;string.h&gt; +#include &lt;stdlib.h&gt; + +struct date +{ + int day; + int month; + int year; +}; + +int compare_dates(struct date d1, struct date d2); + +int main() +{ + struct date date1, date2; + + printf(&quot;Enter Date 1 (dd mm yyyy): &quot;); + scanf(&quot;%d %d %d&quot;, &amp;date1.day, &amp;date1.month, &amp;date1.year); + + printf(&quot;Enter Date 2 (dd mm yyyy): &quot;); + scanf(&quot;%d %d %d&quot;, &amp;date2.day, &amp;date2.month, &amp;date2.year); + + if (compare_dates(date1, date2) == 0) + printf(&quot;The dates are Equal.\n&quot;); + else + printf(&quot;The dates are NOT Equal.\n&quot;); + + return 0; +} + +int compare_dates(struct date d1, struct date d2) +{ + if (d1.day == d2.day &amp;&amp; d1.month == d2.month &amp;&amp; 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 &lt;amitdutta4255@gmail.com&gt; + * 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 &lt;stdio.h&gt; +#include &lt;stdlib.h&gt; +#include &lt;string.h&gt; +#include &lt;ctype.h&gt; + +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(&quot;students.dat&quot;, &quot;rb&quot;); + if (fp == NULL) + { + printf(&quot;Cannot open file!\n&quot;); + exit(1); + } + + // Read records into array + while (fread(&amp;s[count], sizeof(struct student), 1, fp) == 1) + { + count++; + } + fclose(fp); + + // Sort the array + qsort(s, count, sizeof(struct student), compare_names); + + printf(&quot;--- Student List (Sorted by Name) ---\n&quot;); + for (i = 0; i &lt; count; i++) + { + printf(&quot;Name: %-20s Age: %d\n&quot;, s[i].name, s[i].age); + } + + return 0; +} + +int compare_names(const void *a, const void *b) +{ + return strcmp(((struct student *)a)-&gt;name, ((struct student *)b)-&gt;name); +} + +void create_dummy_data() +{ + FILE *fp = fopen(&quot;students.dat&quot;, &quot;wb&quot;); + struct student data[] = { + {&quot;Zack&quot;, 20}, {&quot;Alice&quot;, 19}, {&quot;Bob&quot;, 21}, {&quot;Charlie&quot;, 20}, {&quot;Yasmine&quot;, 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 &lt;amitdutta4255@gmail.com&gt; + * 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 &lt;stdio.h&gt; +#include &lt;stdlib.h&gt; +#include &lt;string.h&gt; +#include &lt;ctype.h&gt; + +void create_source_file(); + +int main() +{ + FILE *fs, *ft; + char ch; + + create_source_file(); // Helper to make code runnable + + fs = fopen(&quot;source.txt&quot;, &quot;r&quot;); + if (fs == NULL) + { + printf(&quot;Cannot open source file.\n&quot;); + exit(1); + } + + ft = fopen(&quot;target.txt&quot;, &quot;w&quot;); + if (ft == NULL) + { + printf(&quot;Cannot open target file.\n&quot;); + fclose(fs); + exit(2); + } + + while ((ch = fgetc(fs)) != EOF) + { + ch = toupper(ch); + fputc(ch, ft); + } + + printf(&quot;File copied successfully with uppercase conversion.\n&quot;); + printf(&quot;Check &#x27;target.txt&#x27; for results.\n&quot;); + + fclose(fs); + fclose(ft); + + return 0; +} + +void create_source_file() +{ + FILE *fp = fopen(&quot;source.txt&quot;, &quot;w&quot;); + if (fp) + { + fprintf(fp, &quot;This is a sample text.\nIt contains Lowercase letters.\n&quot;); + 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 &lt;amitdutta4255@gmail.com&gt; + * 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 &lt;stdio.h&gt; +#include &lt;stdlib.h&gt; +#include &lt;string.h&gt; +#include &lt;ctype.h&gt; + +void create_sample_files(); + +int main() +{ + FILE *fp1, *fp2, *fp3; + char line1[100], line2[100]; + char *res1, *res2; + + create_sample_files(); + + fp1 = fopen(&quot;file1.txt&quot;, &quot;r&quot;); + fp2 = fopen(&quot;file2.txt&quot;, &quot;r&quot;); + fp3 = fopen(&quot;merge.txt&quot;, &quot;w&quot;); + + if (fp1 == NULL || fp2 == NULL || fp3 == NULL) + { + printf(&quot;File error.\n&quot;); + exit(1); + } + + // Read lines from both files + res1 = fgets(line1, sizeof(line1), fp1); + res2 = fgets(line2, sizeof(line2), fp2); + + while (res1 != NULL &amp;&amp; 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(&quot;Files merged alternately into &#x27;merge.txt&#x27;.\n&quot;); + + fclose(fp1); + fclose(fp2); + fclose(fp3); + + return 0; +} + +void create_sample_files() +{ + FILE *f1 = fopen(&quot;file1.txt&quot;, &quot;w&quot;); + FILE *f2 = fopen(&quot;file2.txt&quot;, &quot;w&quot;); + + fprintf(f1, &quot;File 1 - Line A\nFile 1 - Line B\nFile 1 - Line C\n&quot;); + fprintf(f2, &quot;File 2 - Line 1\nFile 2 - Line 2\nFile 2 - Line 3\nFile 2 - Line 4\n&quot;); + + 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 &lt;amitdutta4255@gmail.com&gt; + * 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 &lt;stdio.h&gt; +#include &lt;stdlib.h&gt; +#include &lt;string.h&gt; +#include &lt;ctype.h&gt; + +void create_plain_file(); + +int main() +{ + FILE *fs, *ft; + char ch; + int choice; + + create_plain_file(); + + printf(&quot;1. Offset Cipher\n2. Substitution Cipher\nEnter choice: &quot;); + scanf(&quot;%d&quot;, &amp;choice); + + fs = fopen(&quot;plain.txt&quot;, &quot;r&quot;); + ft = fopen(&quot;coded.txt&quot;, &quot;w&quot;); + + if (fs == NULL || ft == NULL) + { + printf(&quot;Error opening files.\n&quot;); + 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-&gt;!, B-&gt;@ etc. + // Here, we&#x27;ll just map any char to char+5 for simplicity + // as true substitution requires a full map array. + fputc(ch + 5, ft); + } + } + + printf(&quot;Encryption complete. Check &#x27;coded.txt&#x27;.\n&quot;); + + fclose(fs); + fclose(ft); + return 0; +} + +void create_plain_file() +{ + FILE *fp = fopen(&quot;plain.txt&quot;, &quot;w&quot;); + if (fp) + { + fprintf(fp, &quot;SECRET MESSAGE&quot;); + 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 &lt;amitdutta4255@gmail.com&gt; + * 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 &#x27;CUSTOMER.DAT&#x27; balance using &#x27;TRANSACTIONS.DAT&#x27; (Deposit/Withdrawal). Ensure balance doesn&#x27;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 &lt;stdio.h&gt; +#include &lt;stdlib.h&gt; +#include &lt;string.h&gt; +#include &lt;ctype.h&gt; + +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(&quot;CUSTOMER.DAT&quot;, &quot;rb&quot;); + if (fc == NULL) exit(1); + + while (fread(&amp;cust[n_cust], sizeof(struct customer), 1, fc) == 1) + { + n_cust++; + } + fclose(fc); + + // 2. Process transactions sequentially + ft = fopen(&quot;TRANSACTIONS.DAT&quot;, &quot;rb&quot;); + if (ft == NULL) exit(2); + + printf(&quot;Processing Transactions...\n&quot;); + while (fread(&amp;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(&quot;CUSTOMER.DAT&quot;, &quot;wb&quot;); + fwrite(cust, sizeof(struct customer), n_cust, fc); + fclose(fc); + + printf(&quot;Update Complete. New Balances:\n&quot;); + for(i=0; i&lt;n_cust; i++) + printf(&quot;%d %s: %.2f\n&quot;, 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 &lt; n; i++) + { + if (c[i].accno == t.accno) + { + if (t.trans_type == &#x27;D&#x27;) + { + c[i].balance += t.amount; + printf(&quot;Acc %d: Deposited %.2f\n&quot;, t.accno, t.amount); + } + else if (t.trans_type == &#x27;W&#x27;) + { + if ((c[i].balance - t.amount) &gt;= 100) + { + c[i].balance -= t.amount; + printf(&quot;Acc %d: Withdrew %.2f\n&quot;, t.accno, t.amount); + } + else + { + printf(&quot;Acc %d: Withdrawal denied (Min bal constraint)\n&quot;, t.accno); + } + } + return; + } + } + printf(&quot;Transaction Error: Acc %d not found\n&quot;, t.accno); +} + +void create_files() +{ + struct customer c[] = {{101, &quot;A&quot;, 500}, {102, &quot;B&quot;, 1000}, {103, &quot;C&quot;, 200}}; + struct trans t[] = {{101, &#x27;D&#x27;, 200}, {102, &#x27;W&#x27;, 500}, {103, &#x27;W&#x27;, 150}}; // 103 fail + FILE *f1 = fopen(&quot;CUSTOMER.DAT&quot;, &quot;wb&quot;); + FILE *f2 = fopen(&quot;TRANSACTIONS.DAT&quot;, &quot;wb&quot;); + 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 &lt;amitdutta4255@gmail.com&gt; + * 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 &lt;stdio.h&gt; +#include &lt;stdlib.h&gt; +#include &lt;string.h&gt; +#include &lt;ctype.h&gt; + +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(&quot;employee.dat&quot;, &quot;rb&quot;); + if (!fp) return 1; + + while (fread(&amp;e[count], sizeof(struct emp_clean), 1, fp) == 1) + count++; + fclose(fp); + + qsort(e, count, sizeof(struct emp_clean), compare_dates); + + ft = fopen(&quot;emp_sorted.dat&quot;, &quot;wb&quot;); + fwrite(e, sizeof(struct emp_clean), count, ft); + fclose(ft); + + printf(&quot;Sorted records written to &#x27;emp_sorted.dat&#x27;.\nDisplaying sorted list:\n&quot;); + for(i=0; i&lt;count; i++) + printf(&quot;%s - %02d/%02d/%04d\n&quot;, 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-&gt;doj.y != e2-&gt;doj.y) return e1-&gt;doj.y - e2-&gt;doj.y; + if (e1-&gt;doj.m != e2-&gt;doj.m) return e1-&gt;doj.m - e2-&gt;doj.m; + return e1-&gt;doj.d - e2-&gt;doj.d; +} + +void create_emp_file() +{ + struct emp_clean data[] = { + {1, &quot;John&quot;, {12, 5, 2022}, 5000}, + {2, &quot;Jane&quot;, {10, 1, 2020}, 6000}, // Senior + {3, &quot;Bob&quot;, {15, 8, 2021}, 5500} + }; + FILE *f = fopen(&quot;employee.dat&quot;, &quot;wb&quot;); + 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 &lt;amitdutta4255@gmail.com&gt; + * 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 &#x27;blood donors&#x27; file (Name, Address, Age, Blood Type). Print donors with Age &lt; 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 &lt;stdio.h&gt; +#include &lt;stdlib.h&gt; +#include &lt;string.h&gt; +#include &lt;ctype.h&gt; + +struct donor { + char name[21]; // 20 cols + null + char address[41]; // 40 cols + null + int age; // 2 cols -&gt; int + int blood_type; // 1 col -&gt; int +}; + +void create_donor_file(); + +int main() +{ + FILE *fp; + struct donor d; + + create_donor_file(); + + fp = fopen(&quot;donors.dat&quot;, &quot;rb&quot;); + if (!fp) + { + printf(&quot;File error.\n&quot;); + exit(1); + } + + printf(&quot;--- Donors (Age &lt; 25, Type 2) ---\n&quot;); + while (fread(&amp;d, sizeof(struct donor), 1, fp) == 1) + { + if (d.age &lt; 25 &amp;&amp; d.blood_type == 2) + { + printf(&quot;Name: %s | Age: %d | Addr: %s\n&quot;, d.name, d.age, d.address); + } + } + + fclose(fp); + return 0; +} + +void create_donor_file() +{ + struct donor data[] = { + {&quot;Amit&quot;, &quot;Delhi&quot;, 22, 2}, // Match + {&quot;Rahul&quot;, &quot;Mumbai&quot;, 30, 2}, // Old + {&quot;Sumit&quot;, &quot;Pune&quot;, 21, 1}, // Wrong type + {&quot;Priya&quot;, &quot;Goa&quot;, 24, 2} // Match + }; + FILE *f = fopen(&quot;donors.dat&quot;, &quot;wb&quot;); + 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 &lt;amitdutta4255@gmail.com&gt; + * 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 &lt;stdio.h&gt; +#include &lt;stdlib.h&gt; +#include &lt;string.h&gt; +#include &lt;ctype.h&gt; + +void create_name_file(); + +int main() +{ + FILE *fp; + char name[50]; + int n, current = 0, found = 0; + + create_name_file(); + + printf(&quot;Enter value of n to find n-th name: &quot;); + scanf(&quot;%d&quot;, &amp;n); + + fp = fopen(&quot;names.txt&quot;, &quot;r&quot;); + if (!fp) exit(1); + + // Assuming one name per line + while (fgets(name, sizeof(name), fp) != NULL) + { + current++; + if (current == n) + { + printf(&quot;The %d-th name is: %s&quot;, n, name); + found = 1; + break; + } + } + + if (!found) + printf(&quot;Record not found (Only %d names exist).\n&quot;, current); + + fclose(fp); + return 0; +} + +void create_name_file() +{ + FILE *f = fopen(&quot;names.txt&quot;, &quot;w&quot;); + fprintf(f, &quot;Alice\nBob\nCharlie\nDavid\nEve\nFrank\n&quot;); + 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 &lt;amitdutta4255@gmail.com&gt; + * 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 &lt;stdio.h&gt; +#include &lt;stdlib.h&gt; +#include &lt;string.h&gt; +#include &lt;ctype.h&gt; + +struct student { + int roll; + char name[30]; +}; + +struct trans { + int roll; + char code; // &#x27;A&#x27; for Add, &#x27;D&#x27; 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(&quot;MASTER.DAT&quot;, &quot;rb&quot;); + ft = fopen(&quot;TRANS_ROLL.DAT&quot;, &quot;rb&quot;); + fn = fopen(&quot;NEW_MASTER.DAT&quot;, &quot;wb&quot;); + + if (!fm || !ft || !fn) exit(1); + + has_m = fread(&amp;m, sizeof(struct student), 1, fm); + has_t = fread(&amp;t, sizeof(struct trans), 1, ft); + + printf(&quot;Merging Master and Transaction files...\n&quot;); + + while (has_m &amp;&amp; has_t) + { + if (m.roll &lt; t.roll) + { + // No transaction for this master record, keep it + fwrite(&amp;m, sizeof(struct student), 1, fn); + has_m = fread(&amp;m, sizeof(struct student), 1, fm); + } + else if (m.roll == t.roll) + { + // Transaction affects this record + if (t.code == &#x27;D&#x27;) + { + printf(&quot;Deleting Roll %d\n&quot;, m.roll); + // Skip writing &#x27;m&#x27; to file (Deleting) + has_m = fread(&amp;m, sizeof(struct student), 1, fm); + } + else + { + // Logic error: Can&#x27;t ADD if ID exists. Maybe Update? + // Assuming replace or skip. Let&#x27;s skip T and keep M for now. + has_m = fread(&amp;m, sizeof(struct student), 1, fm); + } + has_t = fread(&amp;t, sizeof(struct trans), 1, ft); + } + else // m.roll &gt; t.roll + { + // Transaction ID is new + if (t.code == &#x27;A&#x27;) + { + struct student new_s; + new_s.roll = t.roll; + strcpy(new_s.name, t.name); + fwrite(&amp;new_s, sizeof(struct student), 1, fn); + printf(&quot;Adding Roll %d\n&quot;, new_s.roll); + } + has_t = fread(&amp;t, sizeof(struct trans), 1, ft); + } + } + + // Process remaining Master + while (has_m) + { + fwrite(&amp;m, sizeof(struct student), 1, fn); + has_m = fread(&amp;m, sizeof(struct student), 1, fm); + } + + // Process remaining Transactions (Only Adds) + while (has_t) + { + if (t.code == &#x27;A&#x27;) + { + struct student new_s = {t.roll, &quot;&quot;}; + strcpy(new_s.name, t.name); + fwrite(&amp;new_s, sizeof(struct student), 1, fn); + printf(&quot;Adding Roll %d\n&quot;, new_s.roll); + } + has_t = fread(&amp;t, sizeof(struct trans), 1, ft); + } + + fclose(fm); fclose(ft); fclose(fn); + return 0; +} + +void create_files() +{ + struct student m[] = {{10, &quot;A&quot;}, {20, &quot;B&quot;}, {30, &quot;C&quot;}}; + struct trans t[] = {{15, &#x27;A&#x27;, &quot;NewGuy&quot;}, {20, &#x27;D&#x27;, &quot;&quot;}, {40, &#x27;A&#x27;, &quot;LastGuy&quot;}}; + + FILE *f1 = fopen(&quot;MASTER.DAT&quot;, &quot;wb&quot;); + fwrite(m, sizeof(struct student), 3, f1); + fclose(f1); + + FILE *f2 = fopen(&quot;TRANS_ROLL.DAT&quot;, &quot;wb&quot;); + 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 &lt;amitdutta4255@gmail.com&gt; + * 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 &#x27;a&#x27;, &#x27;the&#x27;, &#x27;an&#x27; 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 &lt;stdio.h&gt; +#include &lt;stdlib.h&gt; +#include &lt;string.h&gt; +#include &lt;ctype.h&gt; + +void create_article_file(); + +int main() +{ + FILE *fp, *ft; + char word[100]; + + create_article_file(); + + fp = fopen(&quot;articles.txt&quot;, &quot;r&quot;); + ft = fopen(&quot;clean.txt&quot;, &quot;w&quot;); + + 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, &quot;%s&quot;, word) != EOF) + { + if (strcasecmp(word, &quot;a&quot;) == 0 || + strcasecmp(word, &quot;an&quot;) == 0 || + strcasecmp(word, &quot;the&quot;) == 0) + { + fputc(&#x27; &#x27;, ft); // Replace with blank + } + else + { + fprintf(ft, &quot;%s &quot;, word); + } + } + + printf(&quot;Processed file. Articles removed in &#x27;clean.txt&#x27;.\n&quot;); + + fclose(fp); + fclose(ft); + return 0; +} + +void create_article_file() +{ + FILE *f = fopen(&quot;articles.txt&quot;, &quot;w&quot;); + fprintf(f, &quot;The quick brown fox jumps over a lazy dog. It was an honour.&quot;); + 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 &lt;amitdutta4255@gmail.com&gt; + * 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 &lt;stdio.h&gt; +#include &lt;stdlib.h&gt; +#include &lt;string.h&gt; +#include &lt;ctype.h&gt; + +int main(int argc, char *argv[]) +{ + FILE *fp; + char ch; + + /* Check if file name is provided */ + if (argc != 2) + { + printf(&quot;Usage: %s &lt;filename&gt;\n&quot;, argv[0]); + exit(1); + } + + fp = fopen(argv[1], &quot;r&quot;); + if (fp == NULL) + { + printf(&quot;Error: Cannot open file &#x27;%s&#x27;\n&quot;, argv[1]); + exit(2); + } + + /* Read and display contents */ + while ((ch = fgetc(fp)) != EOF) + { + printf(&quot;%c&quot;, 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 &lt;amitdutta4255@gmail.com&gt; + * 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 &lt;stdio.h&gt; +#include &lt;stdlib.h&gt; +#include &lt;string.h&gt; +#include &lt;ctype.h&gt; + +int main(int argc, char *argv[]) +{ + FILE *fs, *ft; + char ch; + + /* Check for correct number of arguments */ + if (argc != 3) + { + printf(&quot;Usage: %s &lt;source_file&gt; &lt;target_file&gt;\n&quot;, argv[0]); + exit(1); + } + + fs = fopen(argv[1], &quot;r&quot;); + if (fs == NULL) + { + printf(&quot;Error: Cannot open source file &#x27;%s&#x27;\n&quot;, argv[1]); + exit(2); + } + + ft = fopen(argv[2], &quot;w&quot;); + if (ft == NULL) + { + printf(&quot;Error: Cannot create target file &#x27;%s&#x27;\n&quot;, argv[2]); + fclose(fs); + exit(3); + } + + /* Copy contents */ + while ((ch = fgetc(fs)) != EOF) + { + fputc(ch, ft); + } + + printf(&quot;File copied successfully.\n&quot;); + + 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 &lt;amitdutta4255@gmail.com&gt; + * 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 &lt;old word&gt; &lt;new word&gt; &lt;filename&gt; +*/ +/* 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 &lt;stdio.h&gt; +#include &lt;stdlib.h&gt; +#include &lt;string.h&gt; +#include &lt;ctype.h&gt; + +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(&quot;Usage: %s &lt;old word&gt; &lt;new word&gt; &lt;filename&gt;\n&quot;, argv[0]); + exit(1); + } + + old_word = argv[1]; + new_word = argv[2]; + filename = argv[3]; + + fp = fopen(filename, &quot;r&quot;); + if (fp == NULL) + { + printf(&quot;Error opening file: %s\n&quot;, filename); + exit(2); + } + + // Create a temporary file + ft = fopen(&quot;temp.tmp&quot;, &quot;w&quot;); + if (ft == NULL) + { + printf(&quot;Error creating temporary file.\n&quot;); + 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(&quot;temp.tmp&quot;, filename); + + printf(&quot;Replacement complete.\n&quot;); + + 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 &#x27;str&#x27; 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 &lt; 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 &lt;amitdutta4255@gmail.com&gt; + * 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 &lt;switch&gt; &lt;n&gt; &lt;m&gt;\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 &lt;stdio.h&gt; +#include &lt;stdlib.h&gt; +#include &lt;string.h&gt; +#include &lt;ctype.h&gt; + +int main(int argc, char *argv[]) +{ + float n, m, res; + char operator; + + if (argc != 4) + { + printf(&quot;Usage: %s &lt;switch&gt; &lt;n&gt; &lt;m&gt;\n&quot;, argv[0]); + printf(&quot;Example: %s + 10 20\n&quot;, argv[0]); + printf(&quot;Note: For multiplication (*), use &#x27;*&#x27; or x to avoid shell expansion.\n&quot;); + exit(1); + } + + operator = argv[1][0]; // First character of the switch argument + n = atof(argv[2]); + m = atof(argv[3]); + + switch (operator) + { + // Arithmetic + case &#x27;+&#x27;: + printf(&quot;%.2f\n&quot;, n + m); + break; + case &#x27;-&#x27;: + printf(&quot;%.2f\n&quot;, n - m); + break; + case &#x27;x&#x27;: + case &#x27;*&#x27;: + printf(&quot;%.2f\n&quot;, n * m); + break; + case &#x27;/&#x27;: + if (m == 0) printf(&quot;Error: Division by zero\n&quot;); + else printf(&quot;%.2f\n&quot;, n / m); + break; + case &#x27;%&#x27;: + printf(&quot;%d\n&quot;, (int)n % (int)m); + break; + + // Comparison + case &#x27;&lt;&#x27;: + printf(&quot;%s\n&quot;, (n &lt; m) ? &quot;True&quot; : &quot;False&quot;); + break; + case &#x27;&gt;&#x27;: + printf(&quot;%s\n&quot;, (n &gt; m) ? &quot;True&quot; : &quot;False&quot;); + break; + + // Handling symbols that might be multi-char (e.g. &lt;=, &gt;=, ==) is tricky + // with argv[1][0], but basic logic for typical single char switches: + case &#x27;=&#x27;: + printf(&quot;%s\n&quot;, (n == m) ? &quot;True&quot; : &quot;False&quot;); + break; + + default: + printf(&quot;Unknown operator: %c\n&quot;, 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 &lt;amitdutta4255@gmail.com&gt; + * 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 &#x27;game&#x27; representing sports won by a college. Determine if it won the &#x27;Champion of Champions&#x27; trophy (&gt;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 &lt;stdio.h&gt; +#include &lt;stdlib.h&gt; + +int main() +{ + int game; + int count = 0, i; + const char *sports[] = { + &quot;Cricket&quot;, &quot;Basketball&quot;, &quot;Football&quot;, &quot;Hockey&quot;, + &quot;Lawn Tennis&quot;, &quot;Table Tennis&quot;, &quot;Carom&quot;, &quot;Chess&quot;, &quot;Volleyball&quot; // Added one for bit 8 + }; + + printf(&quot;Enter the game information (integer): &quot;); + scanf(&quot;%d&quot;, &amp;game); + + printf(&quot;\nGames won:\n&quot;); + for (i = 0; i &lt;= 8; i++) + { + if (game &amp; (1 &lt;&lt; i)) + { + printf(&quot;- %s\n&quot;, sports[i]); + count++; + } + } + + printf(&quot;\nTotal games won: %d\n&quot;, count); + + if (count &gt;= 5) + printf(&quot;Result: The college won the Champion of Champions trophy.\n&quot;); + else + printf(&quot;Result: The college did NOT win the trophy.\n&quot;); + + 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 &lt;amitdutta4255@gmail.com&gt; + * 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 &lt;stdio.h&gt; +#include &lt;stdlib.h&gt; + +struct animal +{ + char name[30]; + int type; +}; + +int main() +{ + struct animal a = {&quot;OCELOT&quot;, 18}; + int type = a.type; + + printf(&quot;Animal: %s\n&quot;, a.name); + + // Check Bit 4 for Diet (Assuming 1=Carnivore, 0=Herbivore based on context) + if (type &amp; (1 &lt;&lt; 4)) + printf(&quot;Diet: Carnivore\n&quot;); + else + printf(&quot;Diet: Herbivore\n&quot;); + + // Check Bits 0-3 for Family + printf(&quot;Family: &quot;); + if (type &amp; (1 &lt;&lt; 0)) printf(&quot;Canine &quot;); + if (type &amp; (1 &lt;&lt; 1)) printf(&quot;Feline &quot;); + if (type &amp; (1 &lt;&lt; 2)) printf(&quot;Cetacean &quot;); + if (type &amp; (1 &lt;&lt; 3)) printf(&quot;Marsupial &quot;); + printf(&quot;\n&quot;); + + 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 &lt;amitdutta4255@gmail.com&gt; + * 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 &lt;stdio.h&gt; +#include &lt;stdlib.h&gt; + +int main() +{ + int data[] = {273, 548, 786, 1096}; + int n = 4, i; + int val, year, stream_bits, room; + + for (i = 0; i &lt; n; i++) + { + val = data[i]; + + // Room Number: Rest of the bits (Assuming starting from bit 8) + room = val &gt;&gt; 8; + + printf(&quot;Student %d (Raw: %d):\n&quot;, i + 1, val); + printf(&quot; Room No: %d\n&quot;, room); + + // Year: Bits 0-3 + printf(&quot; Year: &quot;); + if (val &amp; (1 &lt;&lt; 0)) printf(&quot;1st Year&quot;); + else if (val &amp; (1 &lt;&lt; 1)) printf(&quot;2nd Year&quot;); + else if (val &amp; (1 &lt;&lt; 2)) printf(&quot;3rd Year&quot;); + else if (val &amp; (1 &lt;&lt; 3)) printf(&quot;4th Year&quot;); + else printf(&quot;Unknown&quot;); + printf(&quot;\n&quot;); + + // Stream: Bits 4-7 (Mech, Chem, Elec, CS) + printf(&quot; Stream: &quot;); + if (val &amp; (1 &lt;&lt; 4)) printf(&quot;Mechanical&quot;); + else if (val &amp; (1 &lt;&lt; 5)) printf(&quot;Chemical&quot;); + else if (val &amp; (1 &lt;&lt; 6)) printf(&quot;Electronics&quot;); + else if (val &amp; (1 &lt;&lt; 7)) printf(&quot;CS&quot;); + else printf(&quot;Unknown&quot;); + printf(&quot;\n\n&quot;); + } + + 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 &lt;amitdutta4255@gmail.com&gt; + * 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 &lt;stdio.h&gt; +#include &lt;stdlib.h&gt; + +int main() +{ + int i = 32, j = 65, k, l, m, n, o, p; + + k = i | 35; + l = ~k; + m = i &amp; j; + n = j ^ 32; + o = j &lt;&lt; 2; + p = i &gt;&gt; 5; + + printf(&quot;k = %d l = %d m = %d\n&quot;, k, l, m); + printf(&quot;n = %d o = %d p = %d\n&quot;, 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 &lt;amitdutta4255@gmail.com&gt; + * 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 &lt;stdio.h&gt; +#include &lt;stdlib.h&gt; + +int main() +{ + // Binary numbers represented as string literals for reference + // 01011010 + // 11000011 + // 1010101001110101 + // 111100001011010 + + printf(&quot;Binary: 01011010 -&gt; Hex: 0x%X\n&quot;, 0b01011010); + printf(&quot;Binary: 11000011 -&gt; Hex: 0x%X\n&quot;, 0b11000011); + printf(&quot;Binary: 1010101001110101 -&gt; Hex: 0x%X\n&quot;, 0b1010101001110101); + printf(&quot;Binary: 111100001011010 -&gt; Hex: 0x%X\n&quot;, 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 &lt;amitdutta4255@gmail.com&gt; + * 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 &lt;stdio.h&gt; +#include &lt;stdlib.h&gt; + +int main() +{ + int a = 10, b = 20, c = 5; + + printf(&quot;Original values: a=%d, b=%d, c=%d\n&quot;, a, b, c); + + // a = a | 3 + a |= 3; + printf(&quot;a |= 3 -&gt; %d\n&quot;, a); + + // a = a &amp; 0x48 + a &amp;= 0x48; + printf(&quot;a &amp;= 0x48 -&gt; %d\n&quot;, a); + + // b = b ^ 0x22 + b ^= 0x22; + printf(&quot;b ^= 0x22 -&gt; %d\n&quot;, b); + + // c = c &lt;&lt; 2 + c &lt;&lt;= 2; + printf(&quot;c &lt;&lt;= 2 -&gt; %d\n&quot;, 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 &lt;amitdutta4255@gmail.com&gt; + * 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 &#x27;n&#x27; bits starting from position &#x27;p&#x27; 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 &lt;stdio.h&gt; +#include &lt;stdlib.h&gt; + +int checkbits(unsigned int x, int p, int n); + +int main() +{ + unsigned int x; + int p, n; + + printf(&quot;Enter number (x): &quot;); + scanf(&quot;%u&quot;, &amp;x); + printf(&quot;Enter starting position (p) and count (n): &quot;); + scanf(&quot;%d %d&quot;, &amp;p, &amp;n); + + if (checkbits(x, p, n)) + printf(&quot;TRUE: %d bits starting at %d are ON.\n&quot;, n, p); + else + printf(&quot;FALSE: Not all specified bits are ON.\n&quot;); + + 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 &lt;&lt; n) - 1; + + // Shift mask to position p + mask = mask &lt;&lt; p; + + // Check if bits in x match the mask + return (x &amp; 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 &lt;amitdutta4255@gmail.com&gt; + * 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 &lt;stdio.h&gt; +#include &lt;stdlib.h&gt; + +int main() +{ + unsigned char num; + + printf(&quot;Enter an 8-bit integer (0-255): &quot;); + scanf(&quot;%hhu&quot;, &amp;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 &lt;&lt; 3) | (1 &lt;&lt; 6) | (1 &lt;&lt; 7); + + if ((num &amp; mask) == mask) + printf(&quot;Bits 3, 6, and 7 are ALL ON.\n&quot;); + else + printf(&quot;Bits 3, 6, and 7 are NOT all on.\n&quot;); + + 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 &lt;amitdutta4255@gmail.com&gt; + * 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 &lt;stdio.h&gt; +#include &lt;stdlib.h&gt; + +int main() +{ + unsigned short num, swapped; + + printf(&quot;Enter a 16-bit number (0-65535): &quot;); + scanf(&quot;%hu&quot;, &amp;num); + + // Exchange bytes: + // 1. (num &amp; 0xFF00) &gt;&gt; 8 : Move High Byte to Low Byte position + // 2. (num &amp; 0x00FF) &lt;&lt; 8 : Move Low Byte to High Byte position + + swapped = ((num &amp; 0xFF00) &gt;&gt; 8) | ((num &amp; 0x00FF) &lt;&lt; 8); + + printf(&quot;Original: %hu (Hex: 0x%04X)\n&quot;, num, num); + printf(&quot;Swapped: %hu (Hex: 0x%04X)\n&quot;, 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 &lt;amitdutta4255@gmail.com&gt; + * 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 &lt;stdio.h&gt; +#include &lt;stdlib.h&gt; + +int main() +{ + unsigned char num, swapped; + + printf(&quot;Enter an 8-bit number (0-255): &quot;); + scanf(&quot;%hhu&quot;, &amp;num); + + // Exchange nibbles + // (num &amp; 0xF0) &gt;&gt; 4 : High nibble to Low + // (num &amp; 0x0F) &lt;&lt; 4 : Low nibble to High + + swapped = ((num &amp; 0xF0) &gt;&gt; 4) | ((num &amp; 0x0F) &lt;&lt; 4); + + printf(&quot;Original: %d (Hex: 0x%02X)\n&quot;, num, num); + printf(&quot;Swapped: %d (Hex: 0x%02X)\n&quot;, 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 &lt;amitdutta4255@gmail.com&gt; + * 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 &lt;stdio.h&gt; +#include &lt;stdlib.h&gt; + +int main() +{ + unsigned char num, res; + + printf(&quot;Enter an 8-bit number: &quot;); + scanf(&quot;%hhu&quot;, &amp;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(&quot;Original: 0x%02X\n&quot;, num); + printf(&quot;Result: 0x%02X\n&quot;, 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 &lt;amitdutta4255@gmail.com&gt; + * 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 &lt;stdio.h&gt; +#include &lt;stdlib.h&gt; + +int main() +{ + unsigned char num; + unsigned char mask = (1 &lt;&lt; 3) | (1 &lt;&lt; 5); // Bits 3 and 5 + + printf(&quot;Enter an 8-bit number: &quot;); + scanf(&quot;%hhu&quot;, &amp;num); + + if ((num &amp; mask) == mask) + { + printf(&quot;Bits 3 and 5 are ON. Turning them OFF...\n&quot;); + // XOR with mask toggles 1 to 0 (since they are 1) + // OR: AND with complement mask (~mask) + num = num &amp; ~mask; + } + else + { + printf(&quot;Bits 3 and 5 are NOT both ON. No change.\n&quot;); + } + + printf(&quot;Final Value: %d (0x%02X)\n&quot;, 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 &lt;amitdutta4255@gmail.com&gt; + * 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 &lt;stdio.h&gt; +#include &lt;stdlib.h&gt; + +int main() +{ + unsigned char num; + unsigned char mask = (1 &lt;&lt; 3) | (1 &lt;&lt; 5); + + printf(&quot;Enter an 8-bit number: &quot;); + scanf(&quot;%hhu&quot;, &amp;num); + + // Check if bits are OFF. (num &amp; mask) should be 0. + if ((num &amp; mask) == 0) + { + printf(&quot;Bits 3 and 5 are OFF. Turning them ON...\n&quot;); + num = num | mask; + } + else + { + printf(&quot;Bits 3 and 5 are NOT both OFF. No change.\n&quot;); + } + + printf(&quot;Final Value: %d (0x%02X)\n&quot;, 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 &lt;amitdutta4255@gmail.com&gt; + * 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 &lt;stdio.h&gt; +#include &lt;stdlib.h&gt; + +/* _BV(x) macro usually expands to (1 &lt;&lt; x) */ +#define _BV(x) (1 &lt;&lt; x) + +void showbits(unsigned char n); + +int main() +{ + unsigned char num; + + printf(&quot;Enter an 8-bit number: &quot;); + scanf(&quot;%hhu&quot;, &amp;num); + + printf(&quot;Binary representation: &quot;); + showbits(num); + printf(&quot;\n&quot;); + + return 0; +} + +void showbits(unsigned char n) +{ + int i; + unsigned char mask; + + for (i = 7; i &gt;= 0; i--) + { + mask = _BV(i); + if ((n &amp; mask) == 0) + printf(&quot;0&quot;); + else + printf(&quot;1&quot;); + } +}</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 &lt;amitdutta4255@gmail.com&gt; + * 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 &lt;stdio.h&gt; +#include &lt;stdlib.h&gt; +#include &lt;string.h&gt; + +// 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(&quot;Enter details for 10 employees:\n&quot;); + for (i = 0; i &lt; 10; i++) + { + printf(&quot;\nEmployee %d Name: &quot;, i + 1); + scanf(&quot;%s&quot;, emp[i].name); + + printf(&quot;Date of Joining (dd mm yyyy): &quot;); + scanf(&quot;%d %d %d&quot;, &amp;d, &amp;m, &amp;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(&quot;\n--- Employees Sorted by Joining Year ---\n&quot;); + for (i = 0; i &lt; 10; i++) + { + printf(&quot;%-15s | DOJ: %02d-%02d-%d\n&quot;, + 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-&gt;doj.year != e2-&gt;doj.year) + return e1-&gt;doj.year - e2-&gt;doj.year; + + // Secondary sort by Month + if (e1-&gt;doj.month != e2-&gt;doj.month) + return e1-&gt;doj.month - e2-&gt;doj.month; + + // Tertiary sort by Day + return e1-&gt;doj.day - e2-&gt;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 &lt;amitdutta4255@gmail.com&gt; + * 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 &lt;stdio.h&gt; +#include &lt;stdlib.h&gt; +#include &lt;string.h&gt; + +// 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(&quot;--- Enter Policy Holder Details ---\n&quot;); + + printf(&quot;Policy Name: &quot;); + scanf(&quot; %[^\n]s&quot;, p.policy_name); // Reads string with spaces + + printf(&quot;Duration (Years): &quot;); + scanf(&quot;%d&quot;, &amp;temp_dur); + p.duration = temp_dur; + + printf(&quot;Gender (0 for Male, 1 for Female): &quot;); + scanf(&quot;%d&quot;, &amp;temp_gen); + p.gender = temp_gen; + + printf(&quot;Status (0 for Minor, 1 for Major): &quot;); + scanf(&quot;%d&quot;, &amp;temp_stat); + p.status = temp_stat; + + printf(&quot;\n--- Policy Information Stored ---\n&quot;); + printf(&quot;Policy: %s\n&quot;, p.policy_name); + printf(&quot;Duration: %u years\n&quot;, p.duration); + + // Interpret bits for display + printf(&quot;Gender: %s\n&quot;, (p.gender == 1) ? &quot;Female&quot; : &quot;Male&quot;); + printf(&quot;Status: %s\n&quot;, (p.status == 1) ? &quot;Major&quot; : &quot;Minor&quot;); + + printf(&quot;\nSize of structure: %zu bytes\n&quot;, 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 &lt;amitdutta4255@gmail.com&gt; + * 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: +&quot;Six slippery snails slid slowly seaward.&quot; +&quot;Six silppery snails slid slowly seaward.&quot; +*/ +/* 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 &lt;stdio.h&gt; +#include &lt;stdlib.h&gt; +#include &lt;string.h&gt; +#include &lt;stdint.h&gt; + +/* * 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) &amp; (y)) | ((~x) &amp; (z))) +#define G(x, y, z) (((x) &amp; (z)) | ((y) &amp; (~z))) +#define H(x, y, z) ((x) ^ (y) ^ (z)) +#define I(x, y, z) ((y) ^ ((x) | (~z))) + +#define ROTL(x, s) (((x) &lt;&lt; (s)) | ((x) &gt;&gt; (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 &lt; 64; i++, j += 4) + x[i] = ((uint32_t)block[j]) | (((uint32_t)block[j + 1]) &lt;&lt; 8) | + (((uint32_t)block[j + 2]) &lt;&lt; 16) | (((uint32_t)block[j + 3]) &lt;&lt; 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-&gt;size = 0; + ctx-&gt;buffer[0] = 0x67452301; + ctx-&gt;buffer[1] = 0xefcdab89; + ctx-&gt;buffer[2] = 0x98badcfe; + ctx-&gt;buffer[3] = 0x10325476; +} + +void md5Update(MD5Context *ctx, const uint8_t *input, size_t inputLen) { + size_t i, index, partLen; + index = (size_t)((ctx-&gt;size &gt;&gt; 3) &amp; 0x3f); + ctx-&gt;size += (uint64_t)inputLen * 8; + partLen = 64 - index; + + if (inputLen &gt;= partLen) { + memcpy(&amp;ctx-&gt;input[index], input, partLen); + md5Transform(ctx-&gt;buffer, ctx-&gt;input); + for (i = partLen; i + 63 &lt; inputLen; i += 64) + md5Transform(ctx-&gt;buffer, &amp;input[i]); + index = 0; + } else { + i = 0; + } + memcpy(&amp;ctx-&gt;input[index], &amp;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 &lt; 8; i++) + bits[i] = (uint8_t)((ctx-&gt;size &gt;&gt; (i * 8)) &amp; 0xff); + + index = (size_t)((ctx-&gt;size &gt;&gt; 3) &amp; 0x3f); + padLen = (index &lt; 56) ? (56 - index) : (120 - index); + md5Update(ctx, PADDING, padLen); + md5Update(ctx, bits, 8); + + // Encode state into digest + for (int i = 0; i &lt; 16; i++) + digest[i] = (uint8_t)((ctx-&gt;buffer[i &gt;&gt; 2] &gt;&gt; ((i &amp; 3) * 8)) &amp; 0xff); +} +// --- MD5 Implementation End --- + +void print_hash(uint8_t *digest) { + for (int i = 0; i &lt; 16; i++) printf(&quot;%02x&quot;, digest[i]); + printf(&quot;\n&quot;); +} + +int main() { + char str1[] = &quot;Six slippery snails slid slowly seaward.&quot;; + char str2[] = &quot;Six silppery snails slid slowly seaward.&quot;; // Typo &#x27;silppery&#x27; + + uint8_t hash1[16], hash2[16]; + MD5Context ctx; + + printf(&quot;String 1: %s\n&quot;, str1); + md5Init(&amp;ctx); + md5Update(&amp;ctx, (uint8_t*)str1, strlen(str1)); + md5Final(hash1, &amp;ctx); + printf(&quot;MD5: &quot;); + print_hash(hash1); + + printf(&quot;\nString 2: %s\n&quot;, str2); + md5Init(&amp;ctx); + md5Update(&amp;ctx, (uint8_t*)str2, strlen(str2)); + md5Final(hash2, &amp;ctx); + printf(&quot;MD5: &quot;); + print_hash(hash2); + + // Compare + int same = 1; + for(int i=0; i&lt;16; i++) if(hash1[i] != hash2[i]) same = 0; + + printf(&quot;\nConclusion: The MD5 checksums are %s.\n&quot;, same ? &quot;IDENTICAL&quot; : &quot;DIFFERENT&quot;); + if (!same) printf(&quot;(Even a small change in input creates a completely different hash)\n&quot;); + + 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 &lt;amitdutta4255@gmail.com&gt; + * 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 &lt;stdio.h&gt; +#include &lt;stdlib.h&gt; +#include &lt;string.h&gt; +#include &lt;stdint.h&gt; + +/* * 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) &gt;&gt; (b)) | ((a) &lt;&lt; (32-(b)))) +#define CH(x,y,z) (((x) &amp; (y)) ^ (~(x) &amp; (z))) +#define MAJ(x,y,z) (((x) &amp; (y)) ^ ((x) &amp; (z)) ^ ((y) &amp; (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) &gt;&gt; 3)) +#define SIG1(x) (ROTRIGHT(x,17) ^ ROTRIGHT(x,19) ^ ((x) &gt;&gt; 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 &lt; 16; ++i, j += 4) + m[i] = (data[j] &lt;&lt; 24) | (data[j + 1] &lt;&lt; 16) | (data[j + 2] &lt;&lt; 8) | (data[j + 3]); + for (; i &lt; 64; ++i) + m[i] = SIG1(m[i - 2]) + m[i - 7] + SIG0(m[i - 15]) + m[i - 16]; + + a = ctx-&gt;state[0]; b = ctx-&gt;state[1]; c = ctx-&gt;state[2]; d = ctx-&gt;state[3]; + e = ctx-&gt;state[4]; f = ctx-&gt;state[5]; g = ctx-&gt;state[6]; h = ctx-&gt;state[7]; + + for (i = 0; i &lt; 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-&gt;state[0] += a; ctx-&gt;state[1] += b; ctx-&gt;state[2] += c; ctx-&gt;state[3] += d; + ctx-&gt;state[4] += e; ctx-&gt;state[5] += f; ctx-&gt;state[6] += g; ctx-&gt;state[7] += h; +} + +void sha256_init(SHA256_CTX *ctx) { + ctx-&gt;datalen = 0; + ctx-&gt;bitlen = 0; + ctx-&gt;state[0] = 0x6a09e667; ctx-&gt;state[1] = 0xbb67ae85; + ctx-&gt;state[2] = 0x3c6ef372; ctx-&gt;state[3] = 0xa54ff53a; + ctx-&gt;state[4] = 0x510e527f; ctx-&gt;state[5] = 0x9b05688c; + ctx-&gt;state[6] = 0x1f83d9ab; ctx-&gt;state[7] = 0x5be0cd19; +} + +void sha256_update(SHA256_CTX *ctx, const uint8_t data[], size_t len) { + for (size_t i = 0; i &lt; len; ++i) { + ctx-&gt;data[ctx-&gt;datalen] = data[i]; + ctx-&gt;datalen++; + if (ctx-&gt;datalen == 64) { + sha256_transform(ctx, ctx-&gt;data); + ctx-&gt;bitlen += 512; + ctx-&gt;datalen = 0; + } + } +} + +void sha256_final(SHA256_CTX *ctx, uint8_t hash[]) { + uint32_t i = ctx-&gt;datalen; + if (ctx-&gt;datalen &lt; 56) { + ctx-&gt;data[i++] = 0x80; + while (i &lt; 56) ctx-&gt;data[i++] = 0x00; + } else { + ctx-&gt;data[i++] = 0x80; + while (i &lt; 64) ctx-&gt;data[i++] = 0x00; + sha256_transform(ctx, ctx-&gt;data); + memset(ctx-&gt;data, 0, 56); + } + + ctx-&gt;bitlen += ctx-&gt;datalen * 8; + ctx-&gt;data[63] = ctx-&gt;bitlen; + ctx-&gt;data[62] = ctx-&gt;bitlen &gt;&gt; 8; + ctx-&gt;data[61] = ctx-&gt;bitlen &gt;&gt; 16; + ctx-&gt;data[60] = ctx-&gt;bitlen &gt;&gt; 24; + ctx-&gt;data[59] = ctx-&gt;bitlen &gt;&gt; 32; + ctx-&gt;data[58] = ctx-&gt;bitlen &gt;&gt; 40; + ctx-&gt;data[57] = ctx-&gt;bitlen &gt;&gt; 48; + ctx-&gt;data[56] = ctx-&gt;bitlen &gt;&gt; 56; + sha256_transform(ctx, ctx-&gt;data); + + for (i = 0; i &lt; 4; ++i) { + hash[i] = (ctx-&gt;state[0] &gt;&gt; (24 - i * 8)) &amp; 0x000000ff; + hash[i + 4] = (ctx-&gt;state[1] &gt;&gt; (24 - i * 8)) &amp; 0x000000ff; + hash[i + 8] = (ctx-&gt;state[2] &gt;&gt; (24 - i * 8)) &amp; 0x000000ff; + hash[i + 12] = (ctx-&gt;state[3] &gt;&gt; (24 - i * 8)) &amp; 0x000000ff; + hash[i + 16] = (ctx-&gt;state[4] &gt;&gt; (24 - i * 8)) &amp; 0x000000ff; + hash[i + 20] = (ctx-&gt;state[5] &gt;&gt; (24 - i * 8)) &amp; 0x000000ff; + hash[i + 24] = (ctx-&gt;state[6] &gt;&gt; (24 - i * 8)) &amp; 0x000000ff; + hash[i + 28] = (ctx-&gt;state[7] &gt;&gt; (24 - i * 8)) &amp; 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 &lt; 2) { + printf(&quot;Enter filename to checksum (e.g., this_program.exe): &quot;); + scanf(&quot;%s&quot;, filename); + } else { + strcpy(filename, argv[1]); + } + + fp = fopen(filename, &quot;rb&quot;); // Open in binary mode + if (fp == NULL) { + printf(&quot;Error: Could not open file &#x27;%s&#x27;\n&quot;, filename); + return 1; + } + + sha256_init(&amp;ctx); + + while ((bytesRead = fread(buffer, 1, sizeof(buffer), fp)) &gt; 0) { + sha256_update(&amp;ctx, buffer, bytesRead); + } + + sha256_final(&amp;ctx, hash); + fclose(fp); + + printf(&quot;SHA256 Checksum of &#x27;%s&#x27;:\n&quot;, filename); + for (i = 0; i &lt; 32; i++) { + printf(&quot;%02x&quot;, hash[i]); + } + printf(&quot;\n&quot;); + + 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 &lt;amitdutta4255@gmail.com&gt; + * 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 &#x27;libcurl&#x27; library to compile. + Command: gcc luc117.c -o output -lcurl */ + + +#include &lt;stdio.h&gt; +#include &lt;stdlib.h&gt; +#include &lt;string.h&gt; +#include &lt;curl/curl.h&gt; + +/* Pre-requisites: + 1. Install libcurl development package. + 2. Get OpenAI API Key. +*/ + +#define API_KEY &quot;YOUR_OPENAI_API_KEY_HERE&quot; + +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 = &quot;https://api.openai.com/v1/audio/speech&quot;; + const char *data = &quot;{&quot; + &quot;\&quot;model\&quot;: \&quot;tts-1\&quot;,&quot; + &quot;\&quot;input\&quot;: \&quot;Hello! This is a C program talking to you.\&quot;,&quot; + &quot;\&quot;voice\&quot;: \&quot;alloy\&quot;&quot; + &quot;}&quot;; + + struct curl_slist *headers = NULL; + char auth_header[100]; + sprintf(auth_header, &quot;Authorization: Bearer %s&quot;, API_KEY); + + curl_global_init(CURL_GLOBAL_ALL); + curl = curl_easy_init(); + + if(curl) { + // Set Headers + headers = curl_slist_append(headers, &quot;Content-Type: application/json&quot;); + headers = curl_slist_append(headers, auth_header); + + // Open file to save audio + fp = fopen(&quot;output_audio.mp3&quot;, &quot;wb&quot;); + if(!fp) { + printf(&quot;Error opening file for writing.\n&quot;); + 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(&quot;Sending request to OpenAI TTS API...\n&quot;); + res = curl_easy_perform(curl); + + if(res != CURLE_OK) + fprintf(stderr, &quot;curl_easy_perform() failed: %s\n&quot;, curl_easy_strerror(res)); + else + printf(&quot;Audio saved to &#x27;output_audio.mp3&#x27; successfully.\n&quot;); + + // 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 &lt;amitdutta4255@gmail.com&gt; + * 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&#x27;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 &#x27;libcurl&#x27; library to compile. + Command: gcc luc118.c -o output -lcurl */ + + +#include &lt;stdio.h&gt; +#include &lt;stdlib.h&gt; +#include &lt;string.h&gt; +#include &lt;curl/curl.h&gt; + +/* Pre-requisites: + 1. Install libcurl. + 2. Get OpenAI API Key. +*/ + +#define API_KEY &quot;YOUR_OPENAI_API_KEY_HERE&quot; + +int main(void) { + CURL *curl; + CURLcode res; + + const char *url = &quot;https://api.openai.com/v1/images/generations&quot;; + + // JSON Payload: 4 images, 1024x1024 + const char *data = &quot;{&quot; + &quot;\&quot;prompt\&quot;: \&quot;Birds flying in the sky with a computer mouse in their beak\&quot;,&quot; + &quot;\&quot;n\&quot;: 4,&quot; + &quot;\&quot;size\&quot;: \&quot;1024x1024\&quot;&quot; + &quot;}&quot;; + + struct curl_slist *headers = NULL; + char auth_header[100]; + sprintf(auth_header, &quot;Authorization: Bearer %s&quot;, API_KEY); + + curl = curl_easy_init(); + if(curl) { + headers = curl_slist_append(headers, &quot;Content-Type: application/json&quot;); + 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(&quot;Sending request to OpenAI Image API...\n\n&quot;); + res = curl_easy_perform(curl); + + if(res != CURLE_OK) + fprintf(stderr, &quot;curl_easy_perform() failed: %s\n&quot;, curl_easy_strerror(res)); + + printf(&quot;\n\nCheck the JSON output above for &#x27;url&#x27; fields to view images.\n&quot;); + + 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 &lt;amitdutta4255@gmail.com&gt; + * 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 &#x27;libcurl&#x27; library to compile. + Command: gcc luc119.c -o output -lcurl */ + + +#include &lt;stdio.h&gt; +#include &lt;stdlib.h&gt; +#include &lt;string.h&gt; +#include &lt;curl/curl.h&gt; + +/* Pre-requisites: + 1. Install libcurl. + 2. Get OpenAI API Key. +*/ + +#define API_KEY &quot;YOUR_OPENAI_API_KEY_HERE&quot; + +int main(void) { + CURL *curl; + CURLcode res; + + const char *url = &quot;https://api.openai.com/v1/chat/completions&quot;; + + /* We construct the JSON payload manually. + System prompt instructs the model to detect mood. + User prompt is the sentence to analyze. + */ + const char *data = &quot;{&quot; + &quot;\&quot;model\&quot;: \&quot;gpt-3.5-turbo\&quot;,&quot; + &quot;\&quot;messages\&quot;: [&quot; + &quot; {\&quot;role\&quot;: \&quot;system\&quot;, \&quot;content\&quot;: \&quot;You are a helpful assistant. Analyze the mood of the user input sentence. Return only the mood keywords (e.g., admiration, appreciation, anger, joy).\&quot;},&quot; + &quot; {\&quot;role\&quot;: \&quot;user\&quot;, \&quot;content\&quot;: \&quot;I am so impressed by your performance\&quot;}&quot; + &quot;]&quot; + &quot;}&quot;; + + struct curl_slist *headers = NULL; + char auth_header[100]; + sprintf(auth_header, &quot;Authorization: Bearer %s&quot;, API_KEY); + + curl = curl_easy_init(); + if(curl) { + headers = curl_slist_append(headers, &quot;Content-Type: application/json&quot;); + 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(&quot;Analyzing sentence: &#x27;I am so impressed by your performance&#x27;\n&quot;); + printf(&quot;Waiting for OpenAI response...\n\n&quot;); + + // The response will be printed to standard output + res = curl_easy_perform(curl); + + if(res != CURLE_OK) + fprintf(stderr, &quot;curl_easy_perform() failed: %s\n&quot;, curl_easy_strerror(res)); + + printf(&quot;\n\n(Parse the JSON above to extract the &#x27;content&#x27; field)\n&quot;); + + 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" />
© notamitgamer • Site Built: 2026-07-21 13:58:23 UTC • git-mirror commit: 1037f62 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror