diff --git a/jashn/1.c b/jashn/1.c new file mode 100644 index 0000000..17c0ed6 --- /dev/null +++ b/jashn/1.c @@ -0,0 +1,17 @@ +#include + +// 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; +} \ No newline at end of file diff --git a/jashn/2.c b/jashn/2.c new file mode 100644 index 0000000..ecc93e3 --- /dev/null +++ b/jashn/2.c @@ -0,0 +1,26 @@ +#include + +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; +} diff --git a/jashn/3.c b/jashn/3.c new file mode 100644 index 0000000..8756038 --- /dev/null +++ b/jashn/3.c @@ -0,0 +1,35 @@ +#include + +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; +} diff --git a/jashn/4.c b/jashn/4.c new file mode 100644 index 0000000..234faec --- /dev/null +++ b/jashn/4.c @@ -0,0 +1,27 @@ +#include +#include + +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; +} diff --git a/jashn/5.c b/jashn/5.c new file mode 100644 index 0000000..40cacbe --- /dev/null +++ b/jashn/5.c @@ -0,0 +1,36 @@ +#include +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; +} + \ No newline at end of file