From 87fa3a568343cd3ac66331f71d21537160260c75 Mon Sep 17 00:00:00 2001 From: rahul5002 Date: Wed, 23 Oct 2024 11:58:05 +0100 Subject: [PATCH 1/7] Create rahul.txt --- your_name/rahul.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 your_name/rahul.txt diff --git a/your_name/rahul.txt b/your_name/rahul.txt new file mode 100644 index 0000000..95e9047 --- /dev/null +++ b/your_name/rahul.txt @@ -0,0 +1 @@ +I have forgotten what mental peace felt like. From 44c1087b2bd23bff5eefc855313d9d3daaf00812 Mon Sep 17 00:00:00 2001 From: rahul5002 Date: Thu, 24 Oct 2024 11:22:00 +0100 Subject: [PATCH 2/7] Add files via upload Mentorship_assignment --- bubble_sort.c | 70 +++++++++++++++++++++++++++++++++++++++++ determinant_matrix.c | 35 +++++++++++++++++++++ factorial_recursion.c | 17 ++++++++++ string_initial_letter.c | 17 ++++++++++ string_palindrome.c | 31 ++++++++++++++++++ 5 files changed, 170 insertions(+) create mode 100644 bubble_sort.c create mode 100644 determinant_matrix.c create mode 100644 factorial_recursion.c create mode 100644 string_initial_letter.c create mode 100644 string_palindrome.c diff --git a/bubble_sort.c b/bubble_sort.c new file mode 100644 index 0000000..96c4772 --- /dev/null +++ b/bubble_sort.c @@ -0,0 +1,70 @@ +#include + +int main() { + int m,n; + printf("Enter the number of rows: "); + scanf("%d", &m); + printf("Enter the number of columns: "); + scanf("%d", &n); + + int a[m][n], b[m * n]; + for (int i = 0; i < m * n; i++) + { + b[i] = 0; + } + for (int i = 0; i < m; i++) + { + for (int j = 0; j < n; j++) + { + printf("Enter the elements: "); + scanf("%d", &a[i][j]); + b[i * n + j] = a[i][j]; + } + } + printf("Matrix is:\n"); + for (int i = 0; i < m; i++) + { + for (int j = 0; j < n; j++) + { + printf("%d ", a[i][j]); + } + printf("\n"); + } + for (int i = 0; i < m * n - 1; i++) + { + for (int j = 0; j < m * n - i - 1; j++) + { + if (b[j] < b[j + 1]) + { + int temp = b[j]; + b[j] = b[j + 1]; + b[j + 1] = temp; + } + } + } + printf("Descending order is: "); + for (int i = 0; i < m * n; i++) + { + printf("%d ", b[i]); + } + printf("\n"); + for (int i = 0; i < m * n - 1; i++) + { + for (int j = 0; j < m * n - i - 1; j++) + { + if (b[j] > b[j + 1]) + { + int temp = b[j]; + b[j] = b[j + 1]; + b[j + 1] = temp; + } + } + } + printf("Ascending order is: "); + for (int i = 0; i < m * n; i++) + { + printf("%d ", b[i]); + } + printf("\n"); + return 0; +} diff --git a/determinant_matrix.c b/determinant_matrix.c new file mode 100644 index 0000000..9e09765 --- /dev/null +++ b/determinant_matrix.c @@ -0,0 +1,35 @@ +#include +int det_matrix(int matrix[3][3]); +int main() +{ + int a[3][3]; + for (int i = 0; i < 3; i++) + { + for (int j = 0; j < 3; j++) + { + printf("Enter the element at position (%d,%d): ", i, j); + scanf("%d", &a[i][j]); + } + } + printf("Matrix is:\n"); + for (int i = 0; i < 3; i++) + { + for (int j = 0; j < 3; j++) + { + printf("%d ", a[i][j]); + } + printf("\n"); + } + int determinant=det_matrix(a); + printf("Determinant of Matrix is:%d\n",determinant); + return 0; +} +int det_matrix(int matrix[3][3]) +{ + int det = 0; + for (int i = 0; i < 3;i++) + { + det += matrix[0][i] * (matrix[1][(i + 1) % 3] * matrix[2][(i + 2) % 3] - matrix[1][(i + 2) % 3] * matrix[2][(i + 1) % 3]); + } + return det; +} diff --git a/factorial_recursion.c b/factorial_recursion.c new file mode 100644 index 0000000..b6088b8 --- /dev/null +++ b/factorial_recursion.c @@ -0,0 +1,17 @@ +#include +int fact(int num) +{ + if (num == 0) + return 1; + else + return (num * fact(num - 1)); +} +int main() +{ + int num; + printf("Enter a value for factorial: "); + scanf("%d", &num); + int factorial = fact(num); + printf("Factorial of the number is: %d\n",factorial); + return 0; +} diff --git a/string_initial_letter.c b/string_initial_letter.c new file mode 100644 index 0000000..41b2f34 --- /dev/null +++ b/string_initial_letter.c @@ -0,0 +1,17 @@ +#include +#include +int main() +{ + char string[100]; + printf("Enter the string:"); + scanf("%[^\n]%*c", string); + if (string[0] != ' ') + printf("%c", string[0]); + for (int i = 1; i < strlen(string); i++) + { + if (string[i - 1] == ' ' && string[i] != ' ') + printf("%c", string[i]); + } + printf("\n"); + return 0; +} \ No newline at end of file diff --git a/string_palindrome.c b/string_palindrome.c new file mode 100644 index 0000000..87326c1 --- /dev/null +++ b/string_palindrome.c @@ -0,0 +1,31 @@ +#include +#include +void REVERSE(char *string) +{ + char *start = string; + char *end = string + strlen(string) - 1; + char temp; + while (start < end) + { + temp = *start; + *start = *end; + *end = temp; + start++; + end--; + } +} +int main() +{ + char string[100], original_string[100]; +; + printf("Enter the string: "); + scanf("%s", string); + strcpy(original_string, string); + REVERSE(string); + printf("Reversed string: %s\n", string); + if (strcmp(original_string,string)==0) + printf("%s is a palindrome.",original_string); + else + printf("%s is not a palindrome.",original_string); + return 0; +} From a32fd9791e2aabcf20eb33dc0fd30613885421e7 Mon Sep 17 00:00:00 2001 From: rahul5002 Date: Fri, 25 Oct 2024 15:56:34 +0100 Subject: [PATCH 3/7] bubble_sort --- rahul_assignment/bubble_sort | 1 + 1 file changed, 1 insertion(+) create mode 100644 rahul_assignment/bubble_sort diff --git a/rahul_assignment/bubble_sort b/rahul_assignment/bubble_sort new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/rahul_assignment/bubble_sort @@ -0,0 +1 @@ + From 980c7635b2e4598f05ff18502e31a796c9ec0e88 Mon Sep 17 00:00:00 2001 From: rahul5002 Date: Fri, 25 Oct 2024 15:58:41 +0100 Subject: [PATCH 4/7] bubble_sort --- rahul_assignment/bubble_sort | 70 ++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/rahul_assignment/bubble_sort b/rahul_assignment/bubble_sort index 8b13789..f0fe1a1 100644 --- a/rahul_assignment/bubble_sort +++ b/rahul_assignment/bubble_sort @@ -1 +1,71 @@ +#include + +int main() { + int m,n; + printf("Enter the number of rows: "); + scanf("%d", &m); + printf("Enter the number of columns: "); + scanf("%d", &n); + + int a[m][n], b[m * n]; + for (int i = 0; i < m * n; i++) + { + b[i] = 0; + } + for (int i = 0; i < m; i++) + { + for (int j = 0; j < n; j++) + { + printf("Enter the elements: "); + scanf("%d", &a[i][j]); + b[i * n + j] = a[i][j]; + } + } + printf("Matrix is:\n"); + for (int i = 0; i < m; i++) + { + for (int j = 0; j < n; j++) + { + printf("%d ", a[i][j]); + } + printf("\n"); + } + for (int i = 0; i < m * n - 1; i++) + { + for (int j = 0; j < m * n - i - 1; j++) + { + if (b[j] < b[j + 1]) + { + int temp = b[j]; + b[j] = b[j + 1]; + b[j + 1] = temp; + } + } + } + printf("Descending order is: "); + for (int i = 0; i < m * n; i++) + { + printf("%d ", b[i]); + } + printf("\n"); + for (int i = 0; i < m * n - 1; i++) + { + for (int j = 0; j < m * n - i - 1; j++) + { + if (b[j] > b[j + 1]) + { + int temp = b[j]; + b[j] = b[j + 1]; + b[j + 1] = temp; + } + } + } + printf("Ascending order is: "); + for (int i = 0; i < m * n; i++) + { + printf("%d ", b[i]); + } + printf("\n"); + return 0; +} From 85c176c3daf2604ab46e102c2cd027e9990d485b Mon Sep 17 00:00:00 2001 From: rahul5002 Date: Fri, 25 Oct 2024 20:30:23 +0530 Subject: [PATCH 5/7] Add files via upload --- rahul_assignment/determinant_matrix.c | 35 ++++++++++++++++++++++++ rahul_assignment/factorial_recursion.c | 17 ++++++++++++ rahul_assignment/string_initial_letter.c | 17 ++++++++++++ rahul_assignment/string_palindrome.c | 31 +++++++++++++++++++++ 4 files changed, 100 insertions(+) create mode 100644 rahul_assignment/determinant_matrix.c create mode 100644 rahul_assignment/factorial_recursion.c create mode 100644 rahul_assignment/string_initial_letter.c create mode 100644 rahul_assignment/string_palindrome.c diff --git a/rahul_assignment/determinant_matrix.c b/rahul_assignment/determinant_matrix.c new file mode 100644 index 0000000..9e09765 --- /dev/null +++ b/rahul_assignment/determinant_matrix.c @@ -0,0 +1,35 @@ +#include +int det_matrix(int matrix[3][3]); +int main() +{ + int a[3][3]; + for (int i = 0; i < 3; i++) + { + for (int j = 0; j < 3; j++) + { + printf("Enter the element at position (%d,%d): ", i, j); + scanf("%d", &a[i][j]); + } + } + printf("Matrix is:\n"); + for (int i = 0; i < 3; i++) + { + for (int j = 0; j < 3; j++) + { + printf("%d ", a[i][j]); + } + printf("\n"); + } + int determinant=det_matrix(a); + printf("Determinant of Matrix is:%d\n",determinant); + return 0; +} +int det_matrix(int matrix[3][3]) +{ + int det = 0; + for (int i = 0; i < 3;i++) + { + det += matrix[0][i] * (matrix[1][(i + 1) % 3] * matrix[2][(i + 2) % 3] - matrix[1][(i + 2) % 3] * matrix[2][(i + 1) % 3]); + } + return det; +} diff --git a/rahul_assignment/factorial_recursion.c b/rahul_assignment/factorial_recursion.c new file mode 100644 index 0000000..b6088b8 --- /dev/null +++ b/rahul_assignment/factorial_recursion.c @@ -0,0 +1,17 @@ +#include +int fact(int num) +{ + if (num == 0) + return 1; + else + return (num * fact(num - 1)); +} +int main() +{ + int num; + printf("Enter a value for factorial: "); + scanf("%d", &num); + int factorial = fact(num); + printf("Factorial of the number is: %d\n",factorial); + return 0; +} diff --git a/rahul_assignment/string_initial_letter.c b/rahul_assignment/string_initial_letter.c new file mode 100644 index 0000000..41b2f34 --- /dev/null +++ b/rahul_assignment/string_initial_letter.c @@ -0,0 +1,17 @@ +#include +#include +int main() +{ + char string[100]; + printf("Enter the string:"); + scanf("%[^\n]%*c", string); + if (string[0] != ' ') + printf("%c", string[0]); + for (int i = 1; i < strlen(string); i++) + { + if (string[i - 1] == ' ' && string[i] != ' ') + printf("%c", string[i]); + } + printf("\n"); + return 0; +} \ No newline at end of file diff --git a/rahul_assignment/string_palindrome.c b/rahul_assignment/string_palindrome.c new file mode 100644 index 0000000..87326c1 --- /dev/null +++ b/rahul_assignment/string_palindrome.c @@ -0,0 +1,31 @@ +#include +#include +void REVERSE(char *string) +{ + char *start = string; + char *end = string + strlen(string) - 1; + char temp; + while (start < end) + { + temp = *start; + *start = *end; + *end = temp; + start++; + end--; + } +} +int main() +{ + char string[100], original_string[100]; +; + printf("Enter the string: "); + scanf("%s", string); + strcpy(original_string, string); + REVERSE(string); + printf("Reversed string: %s\n", string); + if (strcmp(original_string,string)==0) + printf("%s is a palindrome.",original_string); + else + printf("%s is not a palindrome.",original_string); + return 0; +} From c93d50cba39d99e886926e9fc94a6133fdc7f042 Mon Sep 17 00:00:00 2001 From: rahul5002 Date: Fri, 25 Oct 2024 20:31:29 +0530 Subject: [PATCH 6/7] Add files via upload --- rahul_assignment/bubble_sort.c | 70 ++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 rahul_assignment/bubble_sort.c diff --git a/rahul_assignment/bubble_sort.c b/rahul_assignment/bubble_sort.c new file mode 100644 index 0000000..96c4772 --- /dev/null +++ b/rahul_assignment/bubble_sort.c @@ -0,0 +1,70 @@ +#include + +int main() { + int m,n; + printf("Enter the number of rows: "); + scanf("%d", &m); + printf("Enter the number of columns: "); + scanf("%d", &n); + + int a[m][n], b[m * n]; + for (int i = 0; i < m * n; i++) + { + b[i] = 0; + } + for (int i = 0; i < m; i++) + { + for (int j = 0; j < n; j++) + { + printf("Enter the elements: "); + scanf("%d", &a[i][j]); + b[i * n + j] = a[i][j]; + } + } + printf("Matrix is:\n"); + for (int i = 0; i < m; i++) + { + for (int j = 0; j < n; j++) + { + printf("%d ", a[i][j]); + } + printf("\n"); + } + for (int i = 0; i < m * n - 1; i++) + { + for (int j = 0; j < m * n - i - 1; j++) + { + if (b[j] < b[j + 1]) + { + int temp = b[j]; + b[j] = b[j + 1]; + b[j + 1] = temp; + } + } + } + printf("Descending order is: "); + for (int i = 0; i < m * n; i++) + { + printf("%d ", b[i]); + } + printf("\n"); + for (int i = 0; i < m * n - 1; i++) + { + for (int j = 0; j < m * n - i - 1; j++) + { + if (b[j] > b[j + 1]) + { + int temp = b[j]; + b[j] = b[j + 1]; + b[j + 1] = temp; + } + } + } + printf("Ascending order is: "); + for (int i = 0; i < m * n; i++) + { + printf("%d ", b[i]); + } + printf("\n"); + return 0; +} From e61d0c5627bd063c350287158ac3629ae235d302 Mon Sep 17 00:00:00 2001 From: rahul5002 Date: Fri, 25 Oct 2024 16:04:45 +0100 Subject: [PATCH 7/7] rahul1.txt --- rahul_assignment/bubble_sort | 71 ------------------------------------ rahul_assignment/rahul.txt | 2 + 2 files changed, 2 insertions(+), 71 deletions(-) delete mode 100644 rahul_assignment/bubble_sort create mode 100644 rahul_assignment/rahul.txt diff --git a/rahul_assignment/bubble_sort b/rahul_assignment/bubble_sort deleted file mode 100644 index f0fe1a1..0000000 --- a/rahul_assignment/bubble_sort +++ /dev/null @@ -1,71 +0,0 @@ -#include - -int main() { - int m,n; - printf("Enter the number of rows: "); - scanf("%d", &m); - printf("Enter the number of columns: "); - scanf("%d", &n); - - int a[m][n], b[m * n]; - for (int i = 0; i < m * n; i++) - { - b[i] = 0; - } - for (int i = 0; i < m; i++) - { - for (int j = 0; j < n; j++) - { - printf("Enter the elements: "); - scanf("%d", &a[i][j]); - b[i * n + j] = a[i][j]; - } - } - printf("Matrix is:\n"); - for (int i = 0; i < m; i++) - { - for (int j = 0; j < n; j++) - { - printf("%d ", a[i][j]); - } - printf("\n"); - } - for (int i = 0; i < m * n - 1; i++) - { - for (int j = 0; j < m * n - i - 1; j++) - { - if (b[j] < b[j + 1]) - { - int temp = b[j]; - b[j] = b[j + 1]; - b[j + 1] = temp; - } - } - } - printf("Descending order is: "); - for (int i = 0; i < m * n; i++) - { - printf("%d ", b[i]); - } - printf("\n"); - for (int i = 0; i < m * n - 1; i++) - { - for (int j = 0; j < m * n - i - 1; j++) - { - if (b[j] > b[j + 1]) - { - int temp = b[j]; - b[j] = b[j + 1]; - b[j + 1] = temp; - } - } - } - printf("Ascending order is: "); - for (int i = 0; i < m * n; i++) - { - printf("%d ", b[i]); - } - printf("\n"); - return 0; -} - diff --git a/rahul_assignment/rahul.txt b/rahul_assignment/rahul.txt new file mode 100644 index 0000000..cb0bb5e --- /dev/null +++ b/rahul_assignment/rahul.txt @@ -0,0 +1,2 @@ +I have forgotten what mental peace felt like. +