bsc

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

commit fc81bc5579916f4d79333853a247b7483b4cea7c
parent 045f35702c1246143b303f28ed6334e795f12646
Author: Amit Dutta <amitdutta4255@gmail.com>
Date:   Wed,  1 Oct 2025 18:45:55 +0530

NEW_COMMIT

Diffstat:
ALetusc-exercises/luc015.c | 27+++++++++++++++++++++++++++
ALetusc-exercises/luc015.exe | 0
ALetusc-exercises/luc016.c | 43+++++++++++++++++++++++++++++++++++++++++++
ALetusc-exercises/luc016.exe | 0
ALetusc-exercises/luc017.c | 24++++++++++++++++++++++++
ALetusc-exercises/luc017.exe | 0
ALetusc-exercises/luc018-logic.c | 88+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ALetusc-exercises/luc018.c | 37+++++++++++++++++++++++++++++++++++++
ALetusc-exercises/luc018.exe | 0
9 files changed, 219 insertions(+), 0 deletions(-)

diff --git a/Letusc-exercises/luc015.c b/Letusc-exercises/luc015.c @@ -0,0 +1,26 @@ +/* Given three points (x1, y1), (x2, y2), and (x3, y3), +write a program to check if the three poins fall on one straight line. */ +/* Author - Amit Dutta, Date - 1st OCT, 2025 */ +/* Let Us C, Chap- 3, Page - 53, Qn No.: f(f) */ + +#include <stdio.h> +#include <math.h> +#define EPSILON 0.0001 +// Define a small tolerance value (EPSILON) for safe floating-point comparison +// This is critical because of minor rounding errors in computer arithmetic. +int main() +{ + double x1, x2, x3, y1, y2, y3, area; + printf("Enter the point A(x1, y1) : "); + scanf("%lf %lf", &x1, &y1); + printf("Enter the point B(x2, y2) : "); + scanf("%lf %lf", &x2, &y2); + printf("Enter the point C(x3, y3) : "); + scanf("%lf %lf", &x3, &y3); + area = 0.5 * ((x1 * (y2 - y3)) + (x2 * (y3 - y1)) + (x3 * (y1 - y2))); + if (fabs(area) < EPSILON) // abs() for integer, fabs() for float, double + printf("\nA(%g, %g), B(%g, %g) and C(%g, %g) points fall on one straight line.", x1, y1, x2, y2, x3, y3); + else + printf("\nA(%g, %g), B(%g, %g) and C(%g, %g) points doesn't fall on one straight line.", x1, y1, x2, y2, x3, y3); + return 0; +}+ \ No newline at end of file diff --git a/Letusc-exercises/luc015.exe b/Letusc-exercises/luc015.exe Binary files differ. diff --git a/Letusc-exercises/luc016.c b/Letusc-exercises/luc016.c @@ -0,0 +1,42 @@ +/* Given the coordiantes (x, y) of center of a circle and its radius, +write a program that will determine whether a point lies inside the circle, +on the circle or outside the circle. (Hint : Use sqrt() and pow() functions.) */ +/* Author - Amit Dutta, Date - 1st OCT, 2025 */ +/* Let Us C, Chap- 3, Page - 53, Qn No.: f(g) */ + +#include <stdio.h> +#include <math.h> +// Define a small tolerance value (EPSILON) for reliable floating-point comparison +#define EPSILON 0.0001 + +int main() +{ + double h, k; + double R; + double x, y; + double distance_sq; + printf("Enter the center coordinates (h, k) : "); + scanf("%lf %lf", &h, &k); + printf("Enter the radius (R) : "); + scanf("%lf", &R); + printf("Enter the point P coordinates (x, y) : "); + scanf("%lf %lf", &x, &y); + distance_sq = pow(x - h, 2) + pow(y - k, 2); + double radius_sq = R * R; + // Case 1: On the circle (D^2 = R^2) - Use EPSILON for safety! + if (fabs(distance_sq - radius_sq) < EPSILON) + { + printf("The point P(%g, %g) lies ON THE CIRCLE.\n", x, y); + } + // Case 2: Inside the circle (D^2 < R^2) + else if (distance_sq < radius_sq) + { + printf("The point P(%g, %g) lies INSIDE THE CIRCLE.\n", x, y); + } + // Case 3: Outside the circle (D^2 > R^2) + else + { + printf("The point P(%g, %g) lies OUTSIDE THE CIRCLE.\n", x, y); + } + return 0; +}+ \ No newline at end of file diff --git a/Letusc-exercises/luc016.exe b/Letusc-exercises/luc016.exe Binary files differ. diff --git a/Letusc-exercises/luc017.c b/Letusc-exercises/luc017.c @@ -0,0 +1,23 @@ +/* Given a point (x, y), write a program to find out if it lies on X-axis, Y-axis or origin. */ +/* Author - Amit Dutta, Date - 1st OCT, 2025 */ +/* Let Us C, Chap- 3, Page - 53, Qn No.: f(h) */ + +#include <stdio.h> +#include <math.h> +#define EPSILON 0.00001 + +int main() +{ + double x, y; + printf("Enter the point P(x, y) : "); + scanf("%lf %lf", &x, &y); + if (fabs(x) < EPSILON && fabs(y) < EPSILON) + printf("\nPoint P(%g, %g) lies on the origin.", x, y); + else if (fabs(x) < EPSILON) + printf("\nPoint P(%g, %g) lies on the Y-Axis.", x, y); + else if (fabs(y) < EPSILON) + printf("\nPoint P(%G, %g) lies on the X-Axis.", x, y); + else + printf("\nThe point P(%g, %g) lies in a QUADRANT (not on an axis or the origin).", x, y); + return 0; +}+ \ No newline at end of file diff --git a/Letusc-exercises/luc017.exe b/Letusc-exercises/luc017.exe Binary files differ. diff --git a/Letusc-exercises/luc018-logic.c b/Letusc-exercises/luc018-logic.c @@ -0,0 +1,87 @@ +/* According to Gregorian calender, it was Monday on the date 01/01/01. +Write a program to find out what is the day on 1st January of any input year. */ +/* Author - Amit Dutta, Date - 1st OCT, 2025 */ +/* Let Us C, Chap- 3, Page - 53, Qn No.: f(i) */ + +#include <stdio.h> + +/** + * @brief Determines if a given year is a leap year. + * * The rule: A year is a leap year if it is divisible by 4, UNLESS it is + * divisible by 100 but NOT by 400. + * * @param year The year to check. + * @return 1 if it is a leap year, 0 otherwise. + */ +int is_leap(int year) { + // Check if divisible by 400 OR (divisible by 4 AND not divisible by 100) + if ((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0)) { + return 1; + } + return 0; +} + +/** + * @brief Calculates the day of the week for January 1st of the given year. + * * The base date is 01/01/01, which was a Monday (index 1). + * * Day Mapping: 0:Sunday, 1:Monday, 2:Tuesday, 3:Wednesday, 4:Thursday, 5:Friday, 6:Saturday + */ +int main() { + long long year; // Use long long for year input if years far in the future/past are tested + int i; + long long total_days = 0; + int day_index; + + // Day names array for output + const char *day_names[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; + + printf("Enter the year (e.g., 2025): "); + if (scanf("%lld", &year) != 1 || year < 1) { + printf("Invalid year input. Please enter a positive integer year (>= 1).\n"); + return 1; + } + + // --- Core Logic: Calculate Total Days --- + + // We only need to consider the years that have *passed* before the target year. + // So, we count days from the end of year 0 up to the end of year (year - 1). + int years_passed = year - 1; + + // 1. Calculate the number of leap days up to the end of year (year - 1) + // Formula based on Gregorian calendar rules for years Y-1: + // (Y-1)/4 - (Y-1)/100 + (Y-1)/400 + long long leap_years = years_passed / 4 - years_passed / 100 + years_passed / 400; + + // 2. Total days = (Number of years * 365) + (Number of leap years) + // Note: The loop method (below) is more intuitive but the formula is faster. + // We will use the direct formula for efficiency. + total_days = years_passed * 365 + leap_years; + + // --- Alternate Loop Method (for conceptual simplicity) --- + /* + for (i = 1; i < year; i++) { + total_days += 365; + if (is_leap(i)) { + total_days += 1; // Add 1 for the leap day + } + } + */ + + // --- Determine the Day of the Week --- + + // Since 01/01/01 was Monday (index 1), we use the following setup: + // Index 1 corresponds to Monday. + // The calculation gives the number of days *past* the Monday start (01/01/01). + // The modulo operation gives the remainder (0-6). + + // 0 days elapsed (Year 1): total_days=0. (0 + 1) % 7 = 1 (Monday). Correct. + // 365 days elapsed (Year 2): total_days=365. (365 + 1) % 7 = 2 (Tuesday). Correct. (365 mod 7 = 1, 1+1 = 2) + + day_index = (total_days + 1) % 7; + + // Correct the Day Index to match the array (0:Sun, 1:Mon, ..., 6:Sat) + // The +1 adjusts for the Monday starting point (index 1). + + printf("\nOn January 1st, %lld, the day was: **%s**.\n", year, day_names[day_index]); + + return 0; +}+ \ No newline at end of file diff --git a/Letusc-exercises/luc018.c b/Letusc-exercises/luc018.c @@ -0,0 +1,36 @@ +/* According to Gregorian calender, it was Monday on the date 01/01/01. +if any year is input through the keyboard write a program to find out +what is the day on 1st January of this year. */ +/* Author - Amit Dutta, Date - 1st OCT, 2025 */ +/* Let Us C, Chap- 3, Page - 53, Qn No.: f(i) */ + +#include <stdio.h> + +int is_leap(int year) { + if ((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0)) { + return 1; + } + return 0; +} + +int main() { + long long year; // long long for year input if years far in the future/past are tested + int i; + long long total_days = 0; + int day_index; + + // Day names array for output + const char *day_names[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; + + printf("Enter the year (e.g., 2025): "); + if (scanf("%lld", &year) != 1 || year < 1) { + printf("Invalid year input. Please enter a positive integer year (>= 1).\n"); + return 1; + } + int years_passed = year - 1; + long long leap_years = years_passed / 4 - years_passed / 100 + years_passed / 400; + total_days = years_passed * 365 + leap_years; + day_index = (total_days + 1) % 7; + printf("\nOn January 1st, %lld, the day was: %s.\n", year, day_names[day_index]); + return 0; +}+ \ No newline at end of file diff --git a/Letusc-exercises/luc018.exe b/Letusc-exercises/luc018.exe Binary files differ.
© 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