commit cffa5872fd0a7e553f4336c65586934f4784a4ad
parent 7ecbbae82d4972213a2e87e4a56239ce18b4c8f9
Author: Amit Dutta <amitdutta4255@gmail.com>
Date: Mon, 24 Nov 2025 15:04:18 +0530
new -24112025 .\letusc\lucproblem015, 016
Diffstat:
3 files changed, 206 insertions(+), 2 deletions(-)
diff --git a/docs/index.html b/docs/index.html
@@ -892,7 +892,7 @@ int main()
<div class="flex items-center">
<svg class="w-6 h-6 text-blue-500 mr-4 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"></path></svg>
<span class="font-medium text-gray-800">letusc</span>
- <span class="ml-2 text-sm text-gray-500">(64 files)</span>
+ <span class="ml-2 text-sm text-gray-500">(66 files)</span>
</div>
<div class="flex items-center space-x-4">
<a href="https://github.com/notamitgamer/bsc/tree/main/letusc" target="_blank" class="p-1 rounded-full text-gray-500 hover:bg-gray-200 hover:text-gray-800 transition-colors" onclick="event.stopPropagation()" title="View folder on GitHub">
@@ -4336,7 +4336,7 @@ void stats(double *sum, double *average, double *standardDeviation)
and standard deviation of these numbers. Call this function from main()
and print the result in main() */
/* Author - Amit Dutta, Date - 23th November, 2025 */
-/* Let Us C, Chap - 9, Page 159, Problem 9.1 */
+/* Let Us C, Chap - 9, Page 158, Problem 9.1 */
#include <stdio.h>
#include <math.h>
@@ -4437,6 +4437,122 @@ void stats(double *sum, double *average, double *standardDeviation)
}</code></pre>
</div>
</li>
+
+ <li>
+ <div class="flex items-center p-3 pl-8 hover:bg-gray-50 transition-colors duration-200">
+ <svg class="w-6 h-6 text-green-500 mr-4 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 21h10a2 2 0 002-2V9.414a1 1 0 00-.293-.707l-5.414-5.414A1 1 0 0012.586 3H7a2 2 0 00-2 2v14a2 2 0 002 2z"></path></svg>
+ <span class="text-gray-700">lucproblem015.c</span>
+ <div class="ml-auto flex items-center space-x-4">
+ <a href="https://github.com/notamitgamer/bsc/blob/main/letusc/lucproblem015.c" target="_blank" class="p-1 rounded-full text-gray-500 hover:bg-gray-200 hover:text-gray-800 transition-colors" title="View file on GitHub">
+ <svg class="w-6 h-6" fill="currentColor" viewBox="0 0 24 24" aria-hidden="true"><path fill-rule="evenodd" d="M12 2C6.477 2 2 6.477 2 12c0 4.418 2.865 8.168 6.839 9.492.5.092.682-.217.682-.482 0-.237-.009-.868-.014-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-1.988 1.031-2.688-.103-.253-.446-1.272.098-2.65 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.379.203 2.398.1 2.651.64.7 1.03 1.595 1.03 2.688 0 3.848-2.338 4.695-4.566 4.942.359.308.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.001 10.001 0 0022 12c0-5.523-4.477-10-10-10z" clip-rule="evenodd"></path></svg>
+ </a>
+ <button onclick="showCode('code-letusc-lucproblem015_c', 'lucproblem015.c')" class="text-green-600 font-semibold text-sm hover:underline">View Code</button>
+ </div>
+ </div>
+ <div id="code-letusc-lucproblem015_c" class="hidden" data-github-url="https://github.com/notamitgamer/bsc/blob/main/letusc/lucproblem015.c">
+ <pre><code class="language-c">/* Write a program that defines a function that calculates power of one
+number reaised to another and factorial value of a number in one cell. */
+/* Author - Amit Dutta, Date - 24th November, 2025 */
+/* Let Us C, Chap - 9, Page 159, Problem 9.2 */
+
+#include <stdio.h>
+
+void bothPowerFactorial(double, int, int, double *, long long *);
+
+int main()
+{
+ double a, resultPower;
+ int b, factN;
+ long long resultFactorial;
+ printf("Enter a and b for calculating a raised to b: ");
+ scanf("%lf %d", &a, &b);
+ printf("Enter number to calculate the factorial: ");
+ scanf("%d", &factN);
+ if (b < 0 || factN < 0)
+ {
+ printf("\nOnly non-negative integer is allowed as input of b and factorial.");
+ return 1;
+ }
+ bothPowerFactorial(a, b, factN, &resultPower, &resultFactorial);
+ printf("\n%g Raised to %d: %g"
+ "\nFactorial of %d: %lld",
+ a, b, resultPower, factN, resultFactorial);
+ return 0;
+}
+
+void bothPowerFactorial(double a, int b, int n, double *resultPower, long long *resultFactorial)
+{
+ double tempResultPower = 1;
+ long long tempResultFactorial = 1;
+ int i;
+
+ for (i = 1; i <= b; i++)
+ tempResultPower *= a;
+
+ for (i = 1; i <= n; i++)
+ tempResultFactorial *= i;
+
+ *resultPower = tempResultPower;
+ *resultFactorial = tempResultFactorial;
+}</code></pre>
+ </div>
+ </li>
+
+ <li>
+ <div class="flex items-center p-3 pl-8 hover:bg-gray-50 transition-colors duration-200">
+ <svg class="w-6 h-6 text-green-500 mr-4 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 21h10a2 2 0 002-2V9.414a1 1 0 00-.293-.707l-5.414-5.414A1 1 0 0012.586 3H7a2 2 0 00-2 2v14a2 2 0 002 2z"></path></svg>
+ <span class="text-gray-700">lucproblem016.c</span>
+ <div class="ml-auto flex items-center space-x-4">
+ <a href="https://github.com/notamitgamer/bsc/blob/main/letusc/lucproblem016.c" target="_blank" class="p-1 rounded-full text-gray-500 hover:bg-gray-200 hover:text-gray-800 transition-colors" title="View file on GitHub">
+ <svg class="w-6 h-6" fill="currentColor" viewBox="0 0 24 24" aria-hidden="true"><path fill-rule="evenodd" d="M12 2C6.477 2 2 6.477 2 12c0 4.418 2.865 8.168 6.839 9.492.5.092.682-.217.682-.482 0-.237-.009-.868-.014-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-1.988 1.031-2.688-.103-.253-.446-1.272.098-2.65 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.379.203 2.398.1 2.651.64.7 1.03 1.595 1.03 2.688 0 3.848-2.338 4.695-4.566 4.942.359.308.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.001 10.001 0 0022 12c0-5.523-4.477-10-10-10z" clip-rule="evenodd"></path></svg>
+ </a>
+ <button onclick="showCode('code-letusc-lucproblem016_c', 'lucproblem016.c')" class="text-green-600 font-semibold text-sm hover:underline">View Code</button>
+ </div>
+ </div>
+ <div id="code-letusc-lucproblem016_c" class="hidden" data-github-url="https://github.com/notamitgamer/bsc/blob/main/letusc/lucproblem016.c">
+ <pre><code class="language-c">/* Figure 9.4 shows three memory locations and values stored in them.
+Write a program to declare variables that implement the relationship
+shown. How will you print the values and addresses shown in the figure?
+On which machine the program should be executed to get such addresses?
+
+Figure 9.4:
+ value: 3.14, memory_address: 7fff9489c79c
+ value: 7fff9489c7a0, memory_address: 7fff4fd134b8
+ value: 7fff9489c79c, memory_address: 7fff9489c7a0
+*/
+/* Author - Amit Dutta, Date - 24th November, 2025 */
+/* Let Us C, Chap - 9, Page 160, Problem 9.3 */
+
+#include <stdio.h>
+
+int main()
+{
+ float a = 3.14;
+ float *c = &a;
+ float **b = &c;
+
+ printf("Location 1 (Variable a):\n");
+ printf("Value: %g\n", a);
+ printf("Address: %p\n", (void *)&a);
+ printf("------------------------------\n");
+
+ printf("Location 3 (Variable c: float *):\n");
+ printf("Value (Address stored): %p\n", (void *)c);
+ printf("Address of c itself: %p\n", (void *)&c);
+ printf("Value pointed to (*c): %g\n", *c);
+ printf("------------------------------\n");
+
+ printf("Location 2 (Variable b: float **):\n");
+ printf("Value (Address stored): %p\n", (void *)b);
+ printf("Address of b itself: %p\n", (void *)&b);
+ printf("Value pointed to (*b): %p\n", (void *)*b);
+ printf("Value pointed to (**b): %g\n", **b);
+ printf("------------------------------\n");
+
+ return 0;
+}</code></pre>
+ </div>
+ </li>
</ul>
</div>
</li>
diff --git a/letusc/lucproblem015.c b/letusc/lucproblem015.c
@@ -0,0 +1,45 @@
+/* Write a program that defines a function that calculates power of one
+number reaised to another and factorial value of a number in one cell. */
+/* Author - Amit Dutta, Date - 24th November, 2025 */
+/* Let Us C, Chap - 9, Page 159, Problem 9.2 */
+
+#include <stdio.h>
+
+void bothPowerFactorial(double, int, int, double *, long long *);
+
+int main()
+{
+ double a, resultPower;
+ int b, factN;
+ long long resultFactorial;
+ printf("Enter a and b for calculating a raised to b: ");
+ scanf("%lf %d", &a, &b);
+ printf("Enter number to calculate the factorial: ");
+ scanf("%d", &factN);
+ if (b < 0 || factN < 0)
+ {
+ printf("\nOnly non-negative integer is allowed as input of b and factorial.");
+ return 1;
+ }
+ bothPowerFactorial(a, b, factN, &resultPower, &resultFactorial);
+ printf("\n%g Raised to %d: %g"
+ "\nFactorial of %d: %lld",
+ a, b, resultPower, factN, resultFactorial);
+ return 0;
+}
+
+void bothPowerFactorial(double a, int b, int n, double *resultPower, long long *resultFactorial)
+{
+ double tempResultPower = 1;
+ long long tempResultFactorial = 1;
+ int i;
+
+ for (i = 1; i <= b; i++)
+ tempResultPower *= a;
+
+ for (i = 1; i <= n; i++)
+ tempResultFactorial *= i;
+
+ *resultPower = tempResultPower;
+ *resultFactorial = tempResultFactorial;
+}+
\ No newline at end of file
diff --git a/letusc/lucproblem016.c b/letusc/lucproblem016.c
@@ -0,0 +1,41 @@
+/* Figure 9.4 shows three memory locations and values stored in them.
+Write a program to declare variables that implement the relationship
+shown. How will you print the values and addresses shown in the figure?
+On which machine the program should be executed to get such addresses?
+
+Figure 9.4:
+ value: 3.14, memory_address: 7fff9489c79c
+ value: 7fff9489c7a0, memory_address: 7fff4fd134b8
+ value: 7fff9489c79c, memory_address: 7fff9489c7a0
+*/
+/* Author - Amit Dutta, Date - 24th November, 2025 */
+/* Let Us C, Chap - 9, Page 160, Problem 9.3 */
+
+#include <stdio.h>
+
+int main()
+{
+ float a = 3.14;
+ float *c = &a;
+ float **b = &c;
+
+ printf("Location 1 (Variable a):\n");
+ printf("Value: %g\n", a);
+ printf("Address: %p\n", (void *)&a);
+ printf("------------------------------\n");
+
+ printf("Location 3 (Variable c: float *):\n");
+ printf("Value (Address stored): %p\n", (void *)c);
+ printf("Address of c itself: %p\n", (void *)&c);
+ printf("Value pointed to (*c): %g\n", *c);
+ printf("------------------------------\n");
+
+ printf("Location 2 (Variable b: float **):\n");
+ printf("Value (Address stored): %p\n", (void *)b);
+ printf("Address of b itself: %p\n", (void *)&b);
+ printf("Value pointed to (*b): %p\n", (void *)*b);
+ printf("Value pointed to (**b): %g\n", **b);
+ printf("------------------------------\n");
+
+ return 0;
+}+
\ No newline at end of file