Skip to content
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
38 changes: 38 additions & 0 deletions Mradul_Lakhotiya/bubble_sort.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <stdio.h>
#include <stdlib.h>

void bubble_sort (int n, int arr[]) {
int i=0;
if (n<=1) {
return;
}
//sort
for (int i = 0; i < n - 1; i++) {
if (arr[i] > arr[i + 1]) {
int temp = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = temp;
}
}
bubble_sort (n-1,arr);
}

int main () {
int n; //input the array
printf ("Enter the number Elements : ");
scanf ("%d",&n);

int arr[n];

for (int i=0; i<n; i++) {
printf ("Enter the arr[%d] : ",i);
scanf ("%d",&arr[i]);
}

bubble_sort (n , arr);

printf ("The sorted array is : ");
for (int i=0; i<n; i++) {
printf ("%d\n",arr[i]);
}
}
53 changes: 53 additions & 0 deletions Mradul_Lakhotiya/index_finder.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include <stdio.h>

int finder (int n, int arr[], int find, int low) {
int high, mid;
high = n-1;
mid = (low+high)/2;
if (find == arr[mid]) {
return mid;
} else if (find > arr[mid]) {
finder (n,arr,find,mid + 1);
} else {
finder (mid,arr,find,low);
}
}

int main () {
int n, find, low=0;

printf ("Enter the number Elements : ");
scanf ("%d",&n);

int arr[n];

for (int i=0; i<n; i++) {
printf ("Enter the arr[%d] : ",i);
scanf ("%d",&arr[i]);
}

for (int i=0; i<n; i++) {
int minindex=i;
for (int j= i+1; j<n; j++) {
if (arr[j]<arr[minindex]) {
minindex = j;
}
}
int temp = arr[i];
arr[i] = arr[minindex];
arr[minindex] = temp;
}

printf ("The sorted array is : \n");

for (int i=0; i<n; i++) {
printf ("%d\n",arr[i]);
}

printf ("Enter the elemeten to be found : ");
scanf ("%d",&find);

int mid = finder (n,arr,find,low);

printf ("The index of the Given number is : %d",mid);
}
25 changes: 25 additions & 0 deletions Mradul_Lakhotiya/recursive_function_Fibonacci.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <stdio.h>

void Fabonacci (int i, int j, int n) {
if (n==0) {
return;
}
printf ("%d\n",i);
int temp;
temp = i;
i = j;
j = j + temp;
n--;

Fabonacci (i,j,n);
}

int main () {
int n;
printf ("Enter the number till you want Fibonacci seres : ");
scanf ("%d",&n);

Fabonacci (0,1,n);

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

int powfinder(int num, int pow) {
if (pow == 0) {
return 1;
} else {
return num * powfinder(num, pow - 1);
}
}

int main() {
int num, pow;
printf("Enter the Number: ");
scanf("%d", &num);
printf("Enter the power: ");
scanf("%d", &pow);

int result = powfinder(num, pow);

printf("The Answer is: %d\n", result);

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

int main () {
int n;
printf ("Enter the number Elements : ");
scanf ("%d",&n);
int arr[n];
for (int i=0; i<n; i++) {
printf ("Enter the arr[%d] : ",i);
scanf ("%d",&arr[i]);
}

for (int i=0; i<n; i++) {
int minindex=i;
for (int j= i+1; j<n; j++) {
if (arr[j]<arr[minindex]) {
minindex = j;
}
}
int temp = arr[i];
arr[i] = arr[minindex];
arr[minindex] = temp;
}

printf ("The sorted array is : \n");
for (int i=0; i<n; i++) {
printf ("%d\n",arr[i]);
}
return 0;
}
31 changes: 31 additions & 0 deletions Mradul_Lakhotiya/string_palindrome.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <stdio.h>
#include <string.h>

int main() {
char str[100];
printf("Enter the string: ");
scanf(" %s", str);

int n = strlen(str);
char ostr[n + 1];

strcpy(ostr, str);

int i = 0, j = n - 1;

while (i < j) {
char temp = str[i];
str[i] = str[j];
str[j] = temp;
i++;
j--;
}

if (strcmp(ostr, str) == 0) {
printf("%s is a palindrome.\n", ostr);
} else {
printf("%s is not a palindrome.\n", ostr);
}

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

int main () {
int count=0;
char str[100];
printf ("Enter the string : ");
scanf ("%s",&str);

int n=strlen(str);

for (int i=0; i<n; i++) {
if (str[i]=='a' || str[i]=='e' || str[i]=='i' || str[i]=='o' || str[i]=='u' || str[i]=='A' || str[i]=='E' || str[i]=='I' || str[i]=='O' || str[i]=='U') {
count++;
}
}
printf ("The Number of vovales in thr given sting are %d",count);

return 0;
}