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/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; +} 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/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. + 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; +} 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; +} 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.