Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create rahul.txt #23

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions bubble_sort.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include<stdio.h>

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;
}
35 changes: 35 additions & 0 deletions determinant_matrix.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <stdio.h>
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;
}
17 changes: 17 additions & 0 deletions factorial_recursion.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <stdio.h>
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;
}
70 changes: 70 additions & 0 deletions rahul_assignment/bubble_sort.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include<stdio.h>

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;
}
35 changes: 35 additions & 0 deletions rahul_assignment/determinant_matrix.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <stdio.h>
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;
}
17 changes: 17 additions & 0 deletions rahul_assignment/factorial_recursion.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <stdio.h>
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;
}
2 changes: 2 additions & 0 deletions rahul_assignment/rahul.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
I have forgotten what mental peace felt like.

17 changes: 17 additions & 0 deletions rahul_assignment/string_initial_letter.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include<stdio.h>
#include<string.h>
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;
}
31 changes: 31 additions & 0 deletions rahul_assignment/string_palindrome.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <stdio.h>
#include <string.h>
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;
}
17 changes: 17 additions & 0 deletions string_initial_letter.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include<stdio.h>
#include<string.h>
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;
}
31 changes: 31 additions & 0 deletions string_palindrome.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <stdio.h>
#include <string.h>
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;
}
1 change: 1 addition & 0 deletions your_name/rahul.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I have forgotten what mental peace felt like.