commit 902ebf04ad04ffeb102c380753557963d5966827
parent 46175d1e556a381cb317e77b95dafbef8422a6b3
Author: Amit Dutta <amitdutta4255@gmail.com>
Date: Mon, 22 Dec 2025 20:25:49 +0530
[2025-12-22] .\assignment-scondary\assignment-s-18, 19, 20 : Uploaded assignment-s files.
Diffstat:
4 files changed, 1104 insertions(+), 0 deletions(-)
diff --git a/assignment-secondary/assignment-s-18.c b/assignment-secondary/assignment-s-18.c
@@ -0,0 +1,100 @@
+/*
+ * ======================================================================================
+ * COPYRIGHT (C) 2025 AMIT DUTTA. ALL RIGHTS RESERVED.
+ * ======================================================================================
+ * Repository: https://github.com/notamitgamer
+ * Author : Amit Dutta
+ * License : EDUCATIONAL SOURCE-AVAILABLE LICENSE (ESAL-1.0)
+ * ======================================================================================
+ *
+ * [ IMPORTANT LEGAL NOTICE ]
+ *
+ * 1. PROPRIETARY STATUS:
+ * This software ("The Software") is the intellectual property of Amit Dutta.
+ * It is NOT "Open Source" in the traditional sense. It is "Source-Available"
+ * for educational observation only.
+ *
+ * 2. ACADEMIC INTEGRITY & RESTRICTION:
+ * The use of this code, in whole or in part, for the purpose of submitting
+ * academic assignments, projects, lab reports, or examinations at
+ * WEST BENGAL STATE UNIVERSITY (WBSU) or any other educational institution
+ * is STRICTLY PROHIBITED.
+ *
+ * >>> VIOLATION OF THIS CLAUSE WILL BE REPORTED AS ACADEMIC MISCONDUCT. <<<
+ *
+ * 3. PERMISSIONS:
+ * You are granted a revocable license to:
+ * - Read and study the code to understand algorithms.
+ * - Compile and run the code locally for personal testing.
+ *
+ * 4. NO WARRANTY:
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
+ *
+ * ======================================================================================
+ */
+
+/* Write a program to calculate the factorial of a number
+ (i) using recursion
+ (ii) using iteration
+*/
+
+#include <stdio.h>
+
+long long int fact_tail_rec(int, long long int);
+long long int fact_rec(int);
+long long int fact_ite(int);
+
+int main()
+{
+ int n;
+ printf("Enter the number: ");
+ scanf("%d", &n);
+ if (n < 0)
+ {
+ printf("\nFactorial of negetive number is not possible.");
+ return 1;
+ }
+ printf("\nFactorial of %d (Tail-Recursion) = %lld", n, fact_tail_rec(n, 1));
+ printf("\nFactorial of %d (Recursion) = %lld", n, fact_rec(n));
+ printf("\nFactorial of %d (Iteration) = %lld", n, fact_ite(n));
+ return 0;
+}
+
+long long int fact_tail_rec(int n, long long int result)
+{
+ if (n == 0 || n == 1)
+ {
+ return result;
+ }
+ else
+ {
+ return fact_tail_rec(n - 1, n * result);
+ }
+}
+
+long long int fact_rec(int n)
+{
+ if (n == 0 || n == 1)
+ {
+ return 1;
+ }
+ else
+ {
+ return n * fact_rec(n - 1);
+ }
+}
+
+long long int fact_ite(int n)
+{
+ int i;
+ long long int result = 1;
+ if (n == 0 || n == 1)
+ {
+ return 1;
+ }
+ for (i = 2; i <= n; i++)
+ {
+ result *= i;
+ }
+ return result;
+}+
\ No newline at end of file
diff --git a/assignment-secondary/assignment-s-19.c b/assignment-secondary/assignment-s-19.c
@@ -0,0 +1,96 @@
+/*
+ * ======================================================================================
+ * COPYRIGHT (C) 2025 AMIT DUTTA. ALL RIGHTS RESERVED.
+ * ======================================================================================
+ * Repository: https://github.com/notamitgamer
+ * Author : Amit Dutta
+ * License : EDUCATIONAL SOURCE-AVAILABLE LICENSE (ESAL-1.0)
+ * ======================================================================================
+ *
+ * [ IMPORTANT LEGAL NOTICE ]
+ *
+ * 1. PROPRIETARY STATUS:
+ * This software ("The Software") is the intellectual property of Amit Dutta.
+ * It is NOT "Open Source" in the traditional sense. It is "Source-Available"
+ * for educational observation only.
+ *
+ * 2. ACADEMIC INTEGRITY & RESTRICTION:
+ * The use of this code, in whole or in part, for the purpose of submitting
+ * academic assignments, projects, lab reports, or examinations at
+ * WEST BENGAL STATE UNIVERSITY (WBSU) or any other educational institution
+ * is STRICTLY PROHIBITED.
+ *
+ * >>> VIOLATION OF THIS CLAUSE WILL BE REPORTED AS ACADEMIC MISCONDUCT. <<<
+ *
+ * 3. PERMISSIONS:
+ * You are granted a revocable license to:
+ * - Read and study the code to understand algorithms.
+ * - Compile and run the code locally for personal testing.
+ *
+ * 4. NO WARRANTY:
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
+ *
+ * ======================================================================================
+ */
+
+/* Write a program to calculate the GCD of two numbers
+ (i) using recursion
+ (ii) without recursion
+*/
+
+#include <stdio.h>
+
+int gcd_tail_rec(int, int);
+int gcd_rec(int, int);
+int gcd_ite(int, int);
+
+int main()
+{
+ int a, b;
+ printf("Enter two number: ");
+ scanf("%d %d", &a, &b);
+ if (a < 0)
+ a = -a;
+ if (b < 0)
+ b = -b;
+ printf("\nGCD (Tail-Recursion) of %d and %d is = %d", a, b, gcd_tail_rec(a, b));
+ printf("\nGCD (Recursion) of %d and %d is = %d", a, b, gcd_rec(a, b));
+ printf("\nGCD (Iteration) of %d and %d is = %d", a, b, gcd_ite(a, b));
+ return 0;
+}
+
+int gcd_tail_rec(int a, int b)
+{
+ if (b == 0)
+ {
+ return a;
+ }
+ else
+ {
+ return gcd_tail_rec(b, a % b);
+ }
+}
+
+int gcd_rec(int a, int b)
+{
+ if (b == 0)
+ {
+ return a;
+ }
+ else
+ {
+ return gcd_rec(b, a % b);
+ }
+}
+
+int gcd_ite(int a, int b)
+{
+ int temp;
+ while (b > 0)
+ {
+ temp = b;
+ b = a % b;
+ a = temp;
+ }
+ return a;
+}+
\ No newline at end of file
diff --git a/assignment-secondary/assignment-s-20.c b/assignment-secondary/assignment-s-20.c
@@ -0,0 +1,332 @@
+/*
+ * ======================================================================================
+ * COPYRIGHT (C) 2025 AMIT DUTTA. ALL RIGHTS RESERVED.
+ * Repository : https://github.com/notamitgamer/bsc
+ * License : ESAL-1.0 ( https://aranag.site/license )
+ * ======================================================================================
+ * [ ACADEMIC INTEGRITY WARNING ]
+ * The use of this code for academic assignments at ANY educational institution,
+ * college, or university is STRICTLY PROHIBITED.
+ * Violations will be reported as academic misconduct.
+ * ======================================================================================
+ */
+
+/* Write a menu-driven program to perform the following matrix operations using 2-D
+ arrays and functions:
+ a. Sum
+ b. Difference
+ c. Product
+ d. Transpose
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#define COL_MAX 10
+#define COL_MIN 0
+#define ROW_MAX 10
+#define ROW_MIN 0
+#define TRUE 1
+#define FALSE 0
+
+void input(int ***, int *, int *);
+void display(int **, int, int);
+void clear(int **, int);
+void sum(int **, int **, int, int);
+void difference(int **, int **, int, int);
+void product(int **, int **, int, int, int);
+void transpose(int **, int, int);
+
+int main()
+{
+ int **a = NULL, **b = NULL;
+ int rows_a, rows_b, cols_a, cols_b;
+ int choice;
+
+ while (TRUE)
+ {
+ printf("\n === MENU ===\n"
+ "1. Sum\n"
+ "2. Difference\n"
+ "3. Product\n"
+ "4. Transpose\n"
+ "0. Exit\n");
+ printf("\nEnter your choice: ");
+ scanf("%d", &choice);
+
+ switch (choice)
+ {
+ case 1:
+ input(&a, &rows_a, &cols_a);
+ if (a == NULL)
+ break;
+
+ input(&b, &rows_b, &cols_b);
+ if (b == NULL)
+ {
+ clear(a, rows_a);
+ a = NULL;
+ break;
+ }
+
+ printf("\nMatrix A = \n");
+ display(a, rows_a, cols_a);
+ printf("\nMatrix B = \n");
+ display(b, rows_b, cols_b);
+
+ if (rows_a != rows_b || cols_a != cols_b)
+ {
+ printf("\nOrder of both matrix should be same to calculate sum.");
+ printf("\nInput : Matrix A = [%d x %d]"
+ " Matrix B = [%d x %d]",
+ rows_a, cols_a, rows_b, cols_b);
+
+ clear(a, rows_a);
+ clear(b, rows_b);
+ a = NULL;
+ b = NULL;
+ break;
+ }
+ printf("\nResult = \n");
+ sum(a, b, rows_a, cols_a);
+
+ clear(a, rows_a);
+ clear(b, rows_b);
+ a = NULL;
+ b = NULL;
+
+ break;
+
+ case 2:
+ input(&a, &rows_a, &cols_a);
+ if (a == NULL)
+ break;
+
+ input(&b, &rows_b, &cols_b);
+ if (b == NULL)
+ {
+ clear(a, rows_a);
+ a = NULL;
+ break;
+ }
+
+ printf("\nMatrix A = \n");
+ display(a, rows_a, cols_a);
+ printf("\nMatrix B = \n");
+ display(b, rows_b, cols_b);
+
+ if (rows_a != rows_b || cols_a != cols_b)
+ {
+ printf("\nOrder of both matrix should be same to calculate difference.");
+ printf("\nInput : Matrix A = [%d x %d]"
+ " Matrix B = [%d x %d]",
+ rows_a, cols_a, rows_b, cols_b);
+
+ clear(a, rows_a);
+ clear(b, rows_b);
+ a = NULL;
+ b = NULL;
+ break;
+ }
+ printf("\nResult = \n");
+ difference(a, b, rows_a, cols_a);
+
+ clear(a, rows_a);
+ clear(b, rows_b);
+ a = NULL;
+ b = NULL;
+
+ break;
+
+ case 3:
+ input(&a, &rows_a, &cols_a);
+ if (a == NULL)
+ break;
+
+ input(&b, &rows_b, &cols_b);
+ if (b == NULL)
+ {
+ clear(a, rows_a);
+ a = NULL;
+ break;
+ }
+
+ printf("\nMatrix A = \n");
+ display(a, rows_a, cols_a);
+ printf("\nMatrix B = \n");
+ display(b, rows_b, cols_b);
+
+ if (cols_a != rows_b)
+ {
+ printf("\nColumn count of matrix A should be same as Row count of matrix B.");
+ printf("\nInput : Matrix A = [%d x %d]"
+ " Matrix B = [%d x %d]",
+ rows_a, cols_a, rows_b, cols_b);
+
+ clear(a, rows_a);
+ clear(b, rows_b);
+ a = NULL;
+ b = NULL;
+ break;
+ }
+ printf("\nResult = \n");
+ product(a, b, rows_a, cols_b, cols_a);
+
+ clear(a, rows_a);
+ clear(b, rows_b);
+ a = NULL;
+ b = NULL;
+
+ break;
+
+ case 4:
+ input(&a, &rows_a, &cols_a);
+ if (a == NULL)
+ break;
+
+ printf("\nMatrix = \n");
+ display(a, rows_a, cols_a);
+
+ printf("\nResult = \n");
+ transpose(a, rows_a, cols_a);
+
+ clear(a, rows_a);
+ a = NULL;
+
+ break;
+
+ case 0:
+ printf("\n\nExiting program...\n");
+ return 0;
+
+ default:
+ printf("\nInvalid choice. Please pick a choice from the menu.\n");
+ }
+ }
+}
+
+void input(int ***matrix, int *rows, int *cols)
+{
+ int i, j;
+ printf("\nEnter row and column count (Max : 10 x 10): ");
+ scanf("%d %d", rows, cols);
+
+ if (*rows > ROW_MAX || *cols > COL_MAX || *rows <= ROW_MIN || *cols <= COL_MIN)
+ {
+ printf("\nInvalid dimensions. Limit is 1 to 10.\n");
+ *matrix = NULL;
+ return;
+ }
+
+ *matrix = (int **)malloc(*rows * sizeof(int *));
+
+ for (i = 0; i < *rows; i++)
+ {
+ (*matrix)[i] = (int *)malloc(*cols * sizeof(int));
+ for (j = 0; j < *cols; j++)
+ {
+ printf("Enter element [%d][%d]: ", i + 1, j + 1);
+ scanf("%d", &((*matrix)[i][j]));
+ }
+ }
+}
+
+void display(int **matrix, int rows, int cols)
+{
+ int i, j;
+ for (i = 0; i < rows; i++)
+ {
+ for (j = 0; j < cols; j++)
+ {
+ printf("%d ", matrix[i][j]);
+ }
+ printf("\n");
+ }
+}
+
+void clear(int **matrix, int rows)
+{
+ int i;
+ for (i = 0; i < rows; i++)
+ {
+ free(matrix[i]);
+ }
+ free(matrix);
+}
+
+void sum(int **a, int **b, int rows, int cols)
+{
+ int i, j;
+
+ int **r = (int **)malloc(rows * sizeof(int *));
+ for (i = 0; i < rows; i++)
+ {
+ r[i] = (int *)malloc(cols * sizeof(int));
+ for (j = 0; j < cols; j++)
+ {
+ r[i][j] = a[i][j] + b[i][j];
+ }
+ }
+ display(r, rows, cols);
+ clear(r, rows);
+}
+
+void difference(int **a, int **b, int rows, int cols)
+{
+ int i, j;
+
+ int **r = (int **)malloc(rows * sizeof(int *));
+ for (i = 0; i < rows; i++)
+ {
+ r[i] = (int *)malloc(cols * sizeof(int));
+ for (j = 0; j < cols; j++)
+ {
+ r[i][j] = a[i][j] - b[i][j];
+ }
+ }
+ display(r, rows, cols);
+ clear(r, rows);
+}
+
+void product(int **a, int **b, int rows_a, int cols_b, int common)
+{
+ int i, x, y, z, temp;
+
+ int **r = (int **)malloc(rows_a * sizeof(int *));
+ for (i = 0; i < rows_a; i++)
+ {
+ r[i] = (int *)malloc(cols_b * sizeof(int));
+ }
+
+ for (x = 0; x < rows_a; x++)
+ {
+ for (y = 0; y < cols_b; y++)
+ {
+ temp = 0;
+ for (z = 0; z < common; z++)
+ {
+ temp += a[x][z] * b[z][y];
+ }
+ r[x][y] = temp;
+ }
+ }
+ display(r, rows_a, cols_b);
+ clear(r, rows_a);
+}
+
+void transpose(int **matrix, int rows, int cols)
+{
+ int i, j;
+
+ int **r = (int **)malloc(cols * sizeof(int *));
+ for (i = 0; i < cols; i++)
+ {
+ r[i] = (int *)malloc(rows * sizeof(int));
+ for (j = 0; j < rows; j++)
+ {
+ r[i][j] = matrix[j][i];
+ }
+ }
+ display(r, cols, rows);
+ clear(r, cols);
+}+
\ No newline at end of file
diff --git a/docs/index.html b/docs/index.html
@@ -3808,6 +3808,579 @@ void fib_ite_print(int n)
}</div>
</div>
+ <div class="file-item flex items-center justify-between px-3 py-2 hover:bg-white hover:shadow-sm rounded-lg transition-all group border border-transparent hover:border-slate-100 mb-1">
+ <div class="flex items-center gap-2.5 min-w-0 cursor-pointer flex-1" onclick="showCode('code-assignment-secondary-assignment-s-18-c', 'assignment-s-18.c', 'https://github.com/notamitgamer/bsc/blob/main/assignment-secondary/assignment-s-18.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">assignment-s-18.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/assignment-secondary/assignment-s-18.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-assignment-secondary-assignment-s-18-c" style="display:none;">/*
+ * ======================================================================================
+ * COPYRIGHT (C) 2025 AMIT DUTTA. ALL RIGHTS RESERVED.
+ * ======================================================================================
+ * Repository: https://github.com/notamitgamer
+ * Author : Amit Dutta
+ * License : EDUCATIONAL SOURCE-AVAILABLE LICENSE (ESAL-1.0)
+ * ======================================================================================
+ *
+ * [ IMPORTANT LEGAL NOTICE ]
+ *
+ * 1. PROPRIETARY STATUS:
+ * This software ("The Software") is the intellectual property of Amit Dutta.
+ * It is NOT "Open Source" in the traditional sense. It is "Source-Available"
+ * for educational observation only.
+ *
+ * 2. ACADEMIC INTEGRITY & RESTRICTION:
+ * The use of this code, in whole or in part, for the purpose of submitting
+ * academic assignments, projects, lab reports, or examinations at
+ * WEST BENGAL STATE UNIVERSITY (WBSU) or any other educational institution
+ * is STRICTLY PROHIBITED.
+ *
+ * >>> VIOLATION OF THIS CLAUSE WILL BE REPORTED AS ACADEMIC MISCONDUCT. <<<
+ *
+ * 3. PERMISSIONS:
+ * You are granted a revocable license to:
+ * - Read and study the code to understand algorithms.
+ * - Compile and run the code locally for personal testing.
+ *
+ * 4. NO WARRANTY:
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
+ *
+ * ======================================================================================
+ */
+
+/* Write a program to calculate the factorial of a number
+ (i) using recursion
+ (ii) using iteration
+*/
+
+#include <stdio.h>
+
+long long int fact_tail_rec(int, long long int);
+long long int fact_rec(int);
+long long int fact_ite(int);
+
+int main()
+{
+ int n;
+ printf("Enter the number: ");
+ scanf("%d", &n);
+ if (n < 0)
+ {
+ printf("\nFactorial of negetive number is not possible.");
+ return 1;
+ }
+ printf("\nFactorial of %d (Tail-Recursion) = %lld", n, fact_tail_rec(n, 1));
+ printf("\nFactorial of %d (Recursion) = %lld", n, fact_rec(n));
+ printf("\nFactorial of %d (Iteration) = %lld", n, fact_ite(n));
+ return 0;
+}
+
+long long int fact_tail_rec(int n, long long int result)
+{
+ if (n == 0 || n == 1)
+ {
+ return result;
+ }
+ else
+ {
+ return fact_tail_rec(n - 1, n * result);
+ }
+}
+
+long long int fact_rec(int n)
+{
+ if (n == 0 || n == 1)
+ {
+ return 1;
+ }
+ else
+ {
+ return n * fact_rec(n - 1);
+ }
+}
+
+long long int fact_ite(int n)
+{
+ int i;
+ long long int result = 1;
+ if (n == 0 || n == 1)
+ {
+ return 1;
+ }
+ for (i = 2; i <= n; i++)
+ {
+ result *= i;
+ }
+ return result;
+}</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-assignment-secondary-assignment-s-19-c', 'assignment-s-19.c', 'https://github.com/notamitgamer/bsc/blob/main/assignment-secondary/assignment-s-19.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">assignment-s-19.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/assignment-secondary/assignment-s-19.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-assignment-secondary-assignment-s-19-c" style="display:none;">/*
+ * ======================================================================================
+ * COPYRIGHT (C) 2025 AMIT DUTTA. ALL RIGHTS RESERVED.
+ * ======================================================================================
+ * Repository: https://github.com/notamitgamer
+ * Author : Amit Dutta
+ * License : EDUCATIONAL SOURCE-AVAILABLE LICENSE (ESAL-1.0)
+ * ======================================================================================
+ *
+ * [ IMPORTANT LEGAL NOTICE ]
+ *
+ * 1. PROPRIETARY STATUS:
+ * This software ("The Software") is the intellectual property of Amit Dutta.
+ * It is NOT "Open Source" in the traditional sense. It is "Source-Available"
+ * for educational observation only.
+ *
+ * 2. ACADEMIC INTEGRITY & RESTRICTION:
+ * The use of this code, in whole or in part, for the purpose of submitting
+ * academic assignments, projects, lab reports, or examinations at
+ * WEST BENGAL STATE UNIVERSITY (WBSU) or any other educational institution
+ * is STRICTLY PROHIBITED.
+ *
+ * >>> VIOLATION OF THIS CLAUSE WILL BE REPORTED AS ACADEMIC MISCONDUCT. <<<
+ *
+ * 3. PERMISSIONS:
+ * You are granted a revocable license to:
+ * - Read and study the code to understand algorithms.
+ * - Compile and run the code locally for personal testing.
+ *
+ * 4. NO WARRANTY:
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
+ *
+ * ======================================================================================
+ */
+
+/* Write a program to calculate the GCD of two numbers
+ (i) using recursion
+ (ii) without recursion
+*/
+
+#include <stdio.h>
+
+int gcd_tail_rec(int, int);
+int gcd_rec(int, int);
+int gcd_ite(int, int);
+
+int main()
+{
+ int a, b;
+ printf("Enter two number: ");
+ scanf("%d %d", &a, &b);
+ if (a < 0)
+ a = -a;
+ if (b < 0)
+ b = -b;
+ printf("\nGCD (Tail-Recursion) of %d and %d is = %d", a, b, gcd_tail_rec(a, b));
+ printf("\nGCD (Recursion) of %d and %d is = %d", a, b, gcd_rec(a, b));
+ printf("\nGCD (Iteration) of %d and %d is = %d", a, b, gcd_ite(a, b));
+ return 0;
+}
+
+int gcd_tail_rec(int a, int b)
+{
+ if (b == 0)
+ {
+ return a;
+ }
+ else
+ {
+ return gcd_tail_rec(b, a % b);
+ }
+}
+
+int gcd_rec(int a, int b)
+{
+ if (b == 0)
+ {
+ return a;
+ }
+ else
+ {
+ return gcd_rec(b, a % b);
+ }
+}
+
+int gcd_ite(int a, int b)
+{
+ int temp;
+ while (b > 0)
+ {
+ temp = b;
+ b = a % b;
+ a = temp;
+ }
+ return a;
+}</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-assignment-secondary-assignment-s-20-c', 'assignment-s-20.c', 'https://github.com/notamitgamer/bsc/blob/main/assignment-secondary/assignment-s-20.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">assignment-s-20.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/assignment-secondary/assignment-s-20.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-assignment-secondary-assignment-s-20-c" style="display:none;">/*
+ * ======================================================================================
+ * COPYRIGHT (C) 2025 AMIT DUTTA. ALL RIGHTS RESERVED.
+ * Repository : https://github.com/notamitgamer/bsc
+ * License : ESAL-1.0 ( https://aranag.site/license )
+ * ======================================================================================
+ * [ ACADEMIC INTEGRITY WARNING ]
+ * The use of this code for academic assignments at ANY educational institution,
+ * college, or university is STRICTLY PROHIBITED.
+ * Violations will be reported as academic misconduct.
+ * ======================================================================================
+ */
+
+/* Write a menu-driven program to perform the following matrix operations using 2-D
+ arrays and functions:
+ a. Sum
+ b. Difference
+ c. Product
+ d. Transpose
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#define COL_MAX 10
+#define COL_MIN 0
+#define ROW_MAX 10
+#define ROW_MIN 0
+#define TRUE 1
+#define FALSE 0
+
+void input(int ***, int *, int *);
+void display(int **, int, int);
+void clear(int **, int);
+void sum(int **, int **, int, int);
+void difference(int **, int **, int, int);
+void product(int **, int **, int, int, int);
+void transpose(int **, int, int);
+
+int main()
+{
+ int **a = NULL, **b = NULL;
+ int rows_a, rows_b, cols_a, cols_b;
+ int choice;
+
+ while (TRUE)
+ {
+ printf("\n === MENU ===\n"
+ "1. Sum\n"
+ "2. Difference\n"
+ "3. Product\n"
+ "4. Transpose\n"
+ "0. Exit\n");
+ printf("\nEnter your choice: ");
+ scanf("%d", &choice);
+
+ switch (choice)
+ {
+ case 1:
+ input(&a, &rows_a, &cols_a);
+ if (a == NULL)
+ break;
+
+ input(&b, &rows_b, &cols_b);
+ if (b == NULL)
+ {
+ clear(a, rows_a);
+ a = NULL;
+ break;
+ }
+
+ printf("\nMatrix A = \n");
+ display(a, rows_a, cols_a);
+ printf("\nMatrix B = \n");
+ display(b, rows_b, cols_b);
+
+ if (rows_a != rows_b || cols_a != cols_b)
+ {
+ printf("\nOrder of both matrix should be same to calculate sum.");
+ printf("\nInput : Matrix A = [%d x %d]"
+ " Matrix B = [%d x %d]",
+ rows_a, cols_a, rows_b, cols_b);
+
+ clear(a, rows_a);
+ clear(b, rows_b);
+ a = NULL;
+ b = NULL;
+ break;
+ }
+ printf("\nResult = \n");
+ sum(a, b, rows_a, cols_a);
+
+ clear(a, rows_a);
+ clear(b, rows_b);
+ a = NULL;
+ b = NULL;
+
+ break;
+
+ case 2:
+ input(&a, &rows_a, &cols_a);
+ if (a == NULL)
+ break;
+
+ input(&b, &rows_b, &cols_b);
+ if (b == NULL)
+ {
+ clear(a, rows_a);
+ a = NULL;
+ break;
+ }
+
+ printf("\nMatrix A = \n");
+ display(a, rows_a, cols_a);
+ printf("\nMatrix B = \n");
+ display(b, rows_b, cols_b);
+
+ if (rows_a != rows_b || cols_a != cols_b)
+ {
+ printf("\nOrder of both matrix should be same to calculate difference.");
+ printf("\nInput : Matrix A = [%d x %d]"
+ " Matrix B = [%d x %d]",
+ rows_a, cols_a, rows_b, cols_b);
+
+ clear(a, rows_a);
+ clear(b, rows_b);
+ a = NULL;
+ b = NULL;
+ break;
+ }
+ printf("\nResult = \n");
+ difference(a, b, rows_a, cols_a);
+
+ clear(a, rows_a);
+ clear(b, rows_b);
+ a = NULL;
+ b = NULL;
+
+ break;
+
+ case 3:
+ input(&a, &rows_a, &cols_a);
+ if (a == NULL)
+ break;
+
+ input(&b, &rows_b, &cols_b);
+ if (b == NULL)
+ {
+ clear(a, rows_a);
+ a = NULL;
+ break;
+ }
+
+ printf("\nMatrix A = \n");
+ display(a, rows_a, cols_a);
+ printf("\nMatrix B = \n");
+ display(b, rows_b, cols_b);
+
+ if (cols_a != rows_b)
+ {
+ printf("\nColumn count of matrix A should be same as Row count of matrix B.");
+ printf("\nInput : Matrix A = [%d x %d]"
+ " Matrix B = [%d x %d]",
+ rows_a, cols_a, rows_b, cols_b);
+
+ clear(a, rows_a);
+ clear(b, rows_b);
+ a = NULL;
+ b = NULL;
+ break;
+ }
+ printf("\nResult = \n");
+ product(a, b, rows_a, cols_b, cols_a);
+
+ clear(a, rows_a);
+ clear(b, rows_b);
+ a = NULL;
+ b = NULL;
+
+ break;
+
+ case 4:
+ input(&a, &rows_a, &cols_a);
+ if (a == NULL)
+ break;
+
+ printf("\nMatrix = \n");
+ display(a, rows_a, cols_a);
+
+ printf("\nResult = \n");
+ transpose(a, rows_a, cols_a);
+
+ clear(a, rows_a);
+ a = NULL;
+
+ break;
+
+ case 0:
+ printf("\n\nExiting program...\n");
+ return 0;
+
+ default:
+ printf("\nInvalid choice. Please pick a choice from the menu.\n");
+ }
+ }
+}
+
+void input(int ***matrix, int *rows, int *cols)
+{
+ int i, j;
+ printf("\nEnter row and column count (Max : 10 x 10): ");
+ scanf("%d %d", rows, cols);
+
+ if (*rows > ROW_MAX || *cols > COL_MAX || *rows <= ROW_MIN || *cols <= COL_MIN)
+ {
+ printf("\nInvalid dimensions. Limit is 1 to 10.\n");
+ *matrix = NULL;
+ return;
+ }
+
+ *matrix = (int **)malloc(*rows * sizeof(int *));
+
+ for (i = 0; i < *rows; i++)
+ {
+ (*matrix)[i] = (int *)malloc(*cols * sizeof(int));
+ for (j = 0; j < *cols; j++)
+ {
+ printf("Enter element [%d][%d]: ", i + 1, j + 1);
+ scanf("%d", &((*matrix)[i][j]));
+ }
+ }
+}
+
+void display(int **matrix, int rows, int cols)
+{
+ int i, j;
+ for (i = 0; i < rows; i++)
+ {
+ for (j = 0; j < cols; j++)
+ {
+ printf("%d ", matrix[i][j]);
+ }
+ printf("\n");
+ }
+}
+
+void clear(int **matrix, int rows)
+{
+ int i;
+ for (i = 0; i < rows; i++)
+ {
+ free(matrix[i]);
+ }
+ free(matrix);
+}
+
+void sum(int **a, int **b, int rows, int cols)
+{
+ int i, j;
+
+ int **r = (int **)malloc(rows * sizeof(int *));
+ for (i = 0; i < rows; i++)
+ {
+ r[i] = (int *)malloc(cols * sizeof(int));
+ for (j = 0; j < cols; j++)
+ {
+ r[i][j] = a[i][j] + b[i][j];
+ }
+ }
+ display(r, rows, cols);
+ clear(r, rows);
+}
+
+void difference(int **a, int **b, int rows, int cols)
+{
+ int i, j;
+
+ int **r = (int **)malloc(rows * sizeof(int *));
+ for (i = 0; i < rows; i++)
+ {
+ r[i] = (int *)malloc(cols * sizeof(int));
+ for (j = 0; j < cols; j++)
+ {
+ r[i][j] = a[i][j] - b[i][j];
+ }
+ }
+ display(r, rows, cols);
+ clear(r, rows);
+}
+
+void product(int **a, int **b, int rows_a, int cols_b, int common)
+{
+ int i, x, y, z, temp;
+
+ int **r = (int **)malloc(rows_a * sizeof(int *));
+ for (i = 0; i < rows_a; i++)
+ {
+ r[i] = (int *)malloc(cols_b * sizeof(int));
+ }
+
+ for (x = 0; x < rows_a; x++)
+ {
+ for (y = 0; y < cols_b; y++)
+ {
+ temp = 0;
+ for (z = 0; z < common; z++)
+ {
+ temp += a[x][z] * b[z][y];
+ }
+ r[x][y] = temp;
+ }
+ }
+ display(r, rows_a, cols_b);
+ clear(r, rows_a);
+}
+
+void transpose(int **matrix, int rows, int cols)
+{
+ int i, j;
+
+ int **r = (int **)malloc(cols * sizeof(int *));
+ for (i = 0; i < cols; i++)
+ {
+ r[i] = (int *)malloc(rows * sizeof(int));
+ for (j = 0; j < rows; j++)
+ {
+ r[i][j] = matrix[j][i];
+ }
+ }
+ display(r, cols, rows);
+ clear(r, cols);
+}</div>
+ </div>
+
</div>
</div>