commit 4d3652572f021201d52e67b38d4fd728f4da2095
parent eeda339cb4e5e48eb9bb3f3de198261018d3d459
Author: Amit Dutta <amitdutta4255@gmail.com>
Date: Mon, 17 Nov 2025 12:56:46 +0530
new -17112025 _letusc/lucproblem12, 13
Diffstat:
2 files changed, 70 insertions(+), 0 deletions(-)
diff --git a/letusc/lucproblem012.c b/letusc/lucproblem012.c
@@ -0,0 +1,30 @@
+/* Write a Function power(a, b), to calculate the value of a raised to b */
+/* Author - Amit Dutta, Date - 17th November, 2025 */
+/* Let Us C, Chap - 8, Page - 141, Problem 8.2 */
+
+#include <stdio.h>
+
+double power(double, int);
+
+double power(double a, int b)
+{
+ if (b == 0)
+ return 1;
+ double res = 1;
+ int i;
+ if (b > 0)
+ for (i = 1; i <= b; i++)
+ res *= a;
+ return res;
+}
+
+int main()
+{
+ double a, result;
+ int b;
+ printf("Enter the value and the power (Format A^B) : ");
+ scanf("%lf^%d", &a, &b);
+ result = power(a, b);
+ printf("Result of %g^%d = %g", a, b, result);
+ return 0;
+}+
\ No newline at end of file
diff --git a/letusc/lucproblem013.c b/letusc/lucproblem013.c
@@ -0,0 +1,38 @@
+/* Define a function to convert any given year into its Roman equivalent.
+Use these roman equivalent for decimal numbers : 1 - I, 5 - V, 10 - X,
+50 - L, 100 - C, 500 - D, 1000 - M */
+/* Author - Amit Dutta, Date - 17th November, 2025 */
+/* Let Us C, Chap - 8, Page - 141, Problem 8.3 */
+
+#include <stdio.h>
+
+void romanise(int);
+
+void romanise(int year)
+{
+ int values[] = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
+ const char *romanChar[] = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};
+ // including the two-character subtractive pairs.
+ int i = 0;
+
+ printf("Year %d = ", year);
+ while (year > 0)
+ {
+ if (year >= values[i])
+ {
+ printf("%s", romanChar[i]);
+ year -= values[i];
+ }
+ else
+ i++;
+ }
+}
+
+int main()
+{
+ int year;
+ printf("Enter the year : ");
+ scanf("%d", &year);
+ romanise(year);
+ return 0;
+}+
\ No newline at end of file