Skip to content
Snippets Groups Projects
Commit e1065462 authored by mathias.catala's avatar mathias.catala
Browse files

"update"

parent 1028c267
Branches
No related tags found
No related merge requests found
No preview for this file type
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#include <string.h>
int Prime();
int factoriel(int n);
int perfect(int num);
bool palindrome(int n ,char* mot);
void swap(int* a,int *b);
void bubbleSort(int n, int tab[]);
void insertionSort(int n, int tab[]);
int main(){
int i;
int arr[] = { 64, 34, 25, 12, 22, 11, 90 };
int n = sizeof(arr)/ sizeof(arr[0]);
for (i = 0; i < n; i++)
printf("%d ", arr[i]);
//bubbleSort(n,arr);
insertionSort(n,arr);
printf("\nSorted array: \n");
for (i = 0; i < n; i++)
printf("%d ", arr[i]);
printf("N: %d",n);
//printf("%u",Prime());
//printf("%u ",factoriel(4));
perfect(0);
//perfect(0);
palindrome(0,"kayak");
//palindrome(0,"kayadfk");
}
......@@ -69,21 +91,81 @@ int perfect(int num){
}
}
bool palindrome(int n ,char* mot){
length=strlen(mot)-1
int len=strlen(mot)-(n+1);
if(mot[n]==mot[length]){
if(mot[n]==mot[len]){
if (index+1 ==len ||index==len){
if (n+1 ==len ||n==len){
printf("pal")
return printf("pal");
}
palindrome(index+1,mot);
palindrome(n+1,mot);
}else{
printf("not pal")
printf("not pal");
}
}
void swap(int* a,int *b){
int temp = *a;
*a = *b;
*b = temp;
}
void bubbleSort(int n, int tab[]){
int i,j;
bool swapped;
for (i=0;i<n-1;i++){
swapped = false;
for(j=0;j<n-1;j++){
if(tab[j]>tab[j+1]){
swap(&tab[j],&tab[j+1]);
swapped =true;
}
}
if(!swapped){
break;
}
}
}
void insertionSort(int n, int tab[]){
int i;
bool swapped;
for (i=0;i<n-1;i++){
int tmp = tab[i];
int pos = i;
while(i>0 && tab[pos-1]>tmp){
tab[pos] = tab[pos-1];
pos-=1;
}
tab[pos]= tmp;
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment