diff --git a/a.exe b/a.exe new file mode 100644 index 0000000..3ab44ab Binary files /dev/null and b/a.exe differ diff --git a/bubble_sort.c b/bubble_sort.c new file mode 100644 index 0000000..d091ead --- /dev/null +++ b/bubble_sort.c @@ -0,0 +1,41 @@ +#include<stdio.h> +int main() +{ + int n; + printf("enter the number of elements in the array: "); + scanf("%d",&n); + int arr[n]; + printf("enter the elements in the array:\n"); + for(int i=0; i<n; i++) + { + printf("element[%d]: ",i+1); + scanf("%d",&arr[i]); + } + int temp, swapped; + for(int i=0; i<n-1; i++) + { + swapped=0; + for(int j=0; j<n-1; j++) + { + if(arr[j] > arr[j+1]) + { + temp=arr[j]; + arr[j]= arr[j+1]; + arr[j+1]=temp; + swapped=1; + } + } + if(swapped == 0) + { + break; + } + + } + printf("Sorted array:\n"); + for(int i=0; i<n; i++) + { + printf(" %d ",arr[i]); + } + printf("\n"); + return 0; +} \ No newline at end of file diff --git a/factorial_via_recursion.c b/factorial_via_recursion.c new file mode 100644 index 0000000..73d521e --- /dev/null +++ b/factorial_via_recursion.c @@ -0,0 +1,21 @@ +#include<stdio.h> +int factorial(int n); +int main() +{ + int n; + printf("Enter a number: "); + scanf("%d",&n); + printf("Factorial of %d: %d",n,factorial(n)); + return 0; +} +int factorial(int n) +{ + if (n >= 1) + { + return n*factorial(n-1); + } + else + { + return 1; + } +} \ No newline at end of file diff --git a/first_letter.c b/first_letter.c new file mode 100644 index 0000000..083557f --- /dev/null +++ b/first_letter.c @@ -0,0 +1,11 @@ +#include<stdio.h> +int main() +{ + char word[100]; + printf("Enter a sentence: "); + while(scanf("%s",word) == 1) + { + printf("%c\n",word[0]); + } + return 0; +} \ No newline at end of file diff --git a/matrix_det.c b/matrix_det.c new file mode 100644 index 0000000..9161b95 --- /dev/null +++ b/matrix_det.c @@ -0,0 +1,19 @@ +#include <stdio.h> +int main() +{ + int matrix[2][2]; + int det; + printf("Enter the elements of the 2 x 2 matrix:\n"); + for(int i=0; i<2; i++) + { + for(int j=0; j<2; j++) + { + printf("element [%d][%d]:",i+1, j+1); + scanf("%d",&matrix[i][j]); + } + } + det = (matrix[0][0] * matrix[1][1]) - (matrix[0][1] * matrix[1][0]); + + printf("Determinant:%d\n",det); + return 0; +} \ No newline at end of file diff --git a/palindrome.c b/palindrome.c new file mode 100644 index 0000000..89f277a --- /dev/null +++ b/palindrome.c @@ -0,0 +1,34 @@ +#include<stdio.h> +#include<string.h> +int main() +{ + char str[100]; + char orstr[100]; + char arstr[100]; + + + printf("enter a string: "); + scanf("%s",str); + strcpy(orstr,str); + strcpy(arstr,str); + int first = 0; + int last = strlen(str)-1; + char x; + while(first < last) + { + x = arstr[first]; + arstr[first] = arstr[last]; + arstr[last] = x; + first++; + last--; + } + int val = strcmp(orstr,arstr); + if(val == 0) + { + printf("string is palindrome"); + } + else + { + printf("string is not palindrome"); + } +} \ No newline at end of file