forked from upesacm/Mentorship-2024
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request upesacm#48 from JJ11589/main
Question's
- Loading branch information
Showing
5 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|