Skip to content

Commit

Permalink
Merge pull request upesacm#48 from JJ11589/main
Browse files Browse the repository at this point in the history
Question's
  • Loading branch information
Amit-S-Sahu authored Oct 26, 2024
2 parents 1744ea6 + 24f8915 commit 8314e68
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 0 deletions.
17 changes: 17 additions & 0 deletions jashn/1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <stdio.h>

// creating a function for factorial

int factorial(int n){
if (n==0 || n==1) // if the user wants to find the factorial of 0 or 1 then the answer will return as 1
return 1;
return n * factorial(n-1); // if user wants to find the factorial of number except 0 or 1
} // recursion

int main() {
int num;
printf("enter number");
scanf("%d",&num);
printf("factorial of %d is %d",num,factorial(num));
return 0;
}
26 changes: 26 additions & 0 deletions jashn/2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <stdio.h>

int main() {
char str[100];
int i = 0;

printf("Enter a sentence: ");
scanf(" %s", str); // Reads the whole line including spaces until newline

// Print the first letter if it’s not a space
if (str[0] != ' ') {
printf("%c ", str[0]);
}

// Iterate through the string to find the first letter of each word
while (str[i] != '\0') {
// Check if the current character is the start of a new word
if (str[i] != ' ' && str[i - 1] == ' ') {
printf("%c ", str[i]);
}
i++;
}

printf("\n"); // Newline after output
return 0;
}
35 changes: 35 additions & 0 deletions jashn/3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <stdio.h>

int main() {
int n;
printf("Enter number of elements: "); //size of array or no. of letters
scanf("%d", &n);

int a[n];
printf("Enter %d elements: ", n); // entering the letters in array
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}

// Bubble Sort

for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < n - i - 1; j++) {
if (a[j] > a[j + 1]) {
// Swap a[j] and a[j + 1]
int temp = a[j];
a[j] = a[j + 1];
a[j + 1] = temp;
}
}
}

// Print sorted array
printf("Sorted array: ");
for (int i = 0; i < n; i++) {
printf("%d ", a[i]);
}
printf("\n");

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

int main() {
char str[100];
int length, isPalindrome = 1;

printf("Enter a string: ");
scanf("%s", str); //

length = strlen(str);

for (int i = 0; i < length / 2; i++) {
if (str[i] != str[length - i - 1]) {
isPalindrome = 0; // Not a palindrome if characters don't match
break;
}
}

if (isPalindrome) {
printf("The string is a palindrome.\n");
} else {
printf("The string is not a palindrome.\n");
}

return 0;
}
36 changes: 36 additions & 0 deletions jashn/5.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <stdio.h>
int main()
{

int a[3][3];
int i,j;

// entering the value in the determinant

printf("enter the elements of first matrix:");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++){
scanf("%d",&a[i][j]);
}
printf("\n");
}

//showing the elements given by user in a matrix
printf("matrices entered\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++){
printf("%d\t",a[i][j]);
}
printf("\n");
}

int det;
det= a[0][0]*((a[1][1]*a[2][2])-(a[1][2]*a[2][1]))-
a[0][1]*((a[1][0]*a[2][2])-(a[1][2]*a[2][0]))+
a[0][2]*((a[1][0]*a[2][1])-(a[1][1]*a[2][0]));
printf("%d",det);
return 0;
}

0 comments on commit 8314e68

Please sign in to comment.