Skip to content

Commit

Permalink
Added the File of Sudhanshu Ranjan
Browse files Browse the repository at this point in the history
  • Loading branch information
DevSudhanshuRanjan committed Oct 24, 2024
1 parent 9c6e2b6 commit f0ae0d3
Show file tree
Hide file tree
Showing 6 changed files with 190 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Sudhanshu Ranjan/Factorial.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <stdio.h>

//Making the function called factorial which will be called to find the factorial of the number.
int factorial(int num){
if (num == 0 || num == 1)//Base case of the Stopping Condition.
{
return 1;
}
else return num*factorial(num-1);//Reccursive Code.

}

int main(){

int num;//Decalaring the number
printf("Enter a number of your choice whose factorial you want to get: ");
scanf("%d", &num);
int Fact = factorial(num);//Storing the value of factorial of the number after calling the function.
printf("The factorial of the number %d is %d",num,Fact);
return 0;
}
21 changes: 21 additions & 0 deletions Sudhanshu Ranjan/First_Letter_of_each_word.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <stdio.h>
#include <string.h>

int main(){

char str[100];
gets(str);
printf("%c\n",str[0]);
for (int i = 0; i < 101; i++)
{
if (str[i] == ' ')
{
printf("%c\n",str[i+1]);
}

}
//I am only able to do so in this code.
//Yes, I know there is some error in this code.

return 0;
}
33 changes: 33 additions & 0 deletions Sudhanshu Ranjan/String_Palindrome.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <stdio.h>
#include <string.h>

int main(){

char str[10];
printf("Enter the word of your choice: ");
scanf("%s",str);
int len = strlen(str);
int low = 0, high = len-1;
int checker;
while(low <= high){
if (str[low] == str[high])
{
low++;
high--;
checker = 1;
}
else if (str[low] != str[high])
{
checker = 0;
break;
}
}
if (checker == 1)
{
printf("The string is palindrome.");
}
else{
printf("The string is not a palindrome.");
}
return 0;
}
2 changes: 2 additions & 0 deletions Sudhanshu Ranjan/Sudhanshu_Ranjan.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Hello Everyone,
So one of the fun fact about me is that I love to do code and also I am always eger to learn new things.
75 changes: 75 additions & 0 deletions Sudhanshu Ranjan/determinant_of_matrix.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#include <stdio.h>

void orderof2()
{
int arr[2][2];
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 2; j++)
{
printf("Enter the value at the position [%d][%d]: ", i, j);
scanf("%d", &arr[i][j]);
}
}
printf("The matrix is: \n");
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 2; j++)
{
printf("%d\t", arr[i][j]);
}
printf("\n");
}
int det = (arr[0][0] * arr[1][1]) - (arr[0][1] * arr[1][0]);

printf("The determinant of the matrix of the order 2 X 2 is -> %d",det);
}

void orderof3()
{
int arr[3][3];
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
printf("Enter the value at the position [%d][%d]: ", i, j);
scanf("%d", &arr[i][j]);
}
}
printf("The matrix is: \n");
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
printf("%d\t", arr[i][j]);
}
printf("\n");
}
int det = arr[0][0]*((arr[1][1]*arr[2][2])-(arr[1][2]*arr[2][1])) - arr[0][1]*((arr[1][0]*arr[2][2])-(arr[1][2]*arr[2][0])) + arr[0][2]*((arr[1][0]*arr[2][1])-(arr[1][1]*arr[2][0]));

printf("The determinant of the matrix of the order 3 X 3 is -> %d",det);
}

int main()
{

int num;
printf("Enter the order of the matrix you want to find the determinant of: ");
scanf("%d", &num);
if (num == 2)
{
orderof2();
}
else if (num == 3)
{
orderof3();
}
else
{
printf("Sorry currently I am unable to find the determinant of the matrix of order higher than 3.");
}
/*Sorry I know that I am not able to find the matrix of order higher that of order 3 but this can be done by
reccurssion and taking the base case of the order 2 X 2. But I am unable to code this much at this time but
I am eger to learn this*/
return 0;
}
38 changes: 38 additions & 0 deletions Sudhanshu Ranjan/learn_bubble_sort.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <stdio.h>

void bubble_sort (int arr[],int n){
for (int i = n-1; i >= 0; i--)
{
int didSwap = 0;
for (int j = 0; j <= i-1; j++)
{
if (arr[j] > arr[j+1])
{
int temp = arr[j+1];
arr[j+1] = arr[j];
arr[j] = temp;
didSwap = 1;
}
}
if (didSwap == 0)
{
break;
}

}

}

int main()
{
int arr[] = {13, 46, 24, 52, 20, 9};
int n = sizeof(arr)/sizeof(arr[0]);
bubble_sort(arr,n);

for (int i = 0; i < n; i++)
{
printf("%d\n",arr[i]);
}

return 0;
}

0 comments on commit f0ae0d3

Please sign in to comment.