Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mishthi Nagpal #41

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added a.exe
Binary file not shown.
41 changes: 41 additions & 0 deletions bubble_sort.c
Original file line number Diff line number Diff line change
@@ -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;
}
21 changes: 21 additions & 0 deletions factorial_via_recursion.c
Original file line number Diff line number Diff line change
@@ -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;
}
}
11 changes: 11 additions & 0 deletions first_letter.c
Original file line number Diff line number Diff line change
@@ -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;
}
19 changes: 19 additions & 0 deletions matrix_det.c
Original file line number Diff line number Diff line change
@@ -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;
}
34 changes: 34 additions & 0 deletions palindrome.c
Original file line number Diff line number Diff line change
@@ -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");
}
}