Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • main
1 result

Target

Select target project
  • algorithmique/cours
  • aurelien.boyer/cours
  • jeremy.meissner/cours
  • radhwan.hassine/cours
  • yassin.elhakoun/cours-algo
  • gaspard.legouic/cours
  • joachim.bach/cours
  • gabriel.marinoja/algo-cours
  • loic.lavorel/cours
  • iliya.saroukha/cours
  • costanti.volta/cours
  • jacquesw.ndoumben/cours
12 results
Select Git revision
  • master
  • radhwan.hassine-master-patch-03421
  • radhwan.hassine-master-patch-79254
3 results
Show changes
Showing
with 4908 additions and 659 deletions
This diff is collapsed.
This diff is collapsed.
---
title: "Introduction aux algorithmes"
date: "2023-10-03"
title: "Introduction aux algorithmes III"
date: "2024-09-30"
---
# Rappel (1/2)
......@@ -258,6 +258,7 @@ for (int i = 0; i < SIZE; ++i) {
tab[i] = rand() / (double)RAND_MAX * 10.0 - 5.0;
// tab[i] contient un double dans [-5;5]
}
int other_tab[4] = {0}; // pareil que {0, 0, 0, 0}
```
# Recherche du minimum dans un tableau (1/2)
......@@ -289,7 +290,7 @@ pour i de 1 à SIZE - 1
int index = 0;
float min = tab[0];
for (int i = 1; i < SIZE; ++i) {
if min > tab[i] {
if (min > tab[i]) {
min = tab[i];
index = i;
}
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define SIZE 10
int tab_find_min_index(int i, int size, char tab[size]) {
int i_min = i;
for (int j = i + 1; j < (int)strlen(tab); ++j) {
if (tab[j] < tab[i_min]) {
i_min = j;
}
}
return i_min;
}
void swap(int i, int j, char tab[]) {
char tmp = tab[i];
tab[i] = tab[j];
tab[j] = tmp;
}
void tab_selection_sort(int size, char tab[size]) {
for (int i = 0; i < (int)strlen(tab); ++i) {
int i_min = tab_find_min_index(i, size, tab);
// échange tab[i] et tab[j]
if (i_min != i) {
swap(i, i_min, tab);
}
}
}
bool tab_is_sorted(int size, char tab[size]) {
for (int i = 1; i < size; ++i) {
if (tab[i - 1] > tab[i]) {
return false;
}
}
return true;
}
int main() {
// allocate tab
char tab_lhs[SIZE] = "tutut";
char tab_rhs[SIZE] = "tutta";
printf("Are %s and %s anagrams? ", tab_lhs, tab_rhs);
tab_selection_sort(SIZE, tab_lhs);
tab_selection_sort(SIZE, tab_rhs);
printf("Are %s and %s anagrams? ", tab_lhs, tab_rhs);
int is_equal = strcmp(tab_lhs, tab_rhs);
printf("%d", is_equal);
}
#include <stdio.h>
#include <strings.h>
#define SIZE 4
int main() {
int tab[SIZE] = {1, -1, 10, 4};
int new_tab[SIZE];
for (int index = 0; index < SIZE - 1; ++index) {
int min_index = index;
int min = tab[min_index];
for (int i = min_index + 1; i < SIZE; ++i) {
if (tab[i] < min) {
min = tab[i];
min_index = i;
}
}
new_tab[index] = min;
}
for (int i = 0; i < SIZE; ++i) {
printf("%d ", new_tab[i]);
}
printf("\n");
}
This diff is collapsed.
This diff is collapsed.
#include <stdio.h>
int factorial(int n) {
if (n > 1) {
return n * factorial(n - 1);
} else {
return 1;
}
}
int main() {
int n = 1000000000;
printf("%d! = %d\n", n, factorial(n));
return 0;
}
CC:=gcc
CFLAGS:=-Wall -Wextra -pedantic -fsanitize=address -g
LDFLAGS:=-fsanitize=address
main: main.o hm.o
main.o: hm.h
hm.o: hm.h
.PHONY: clean
clean:
rm -f *.o main
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#define NX 50
#define NY 100
int main() {
// allocate a 2d array for 50 x 100 of integers
int tab[NX][NY];
// fill the array with random values from 0 to 255 (inclusive)
srand(time(NULL));
for (int i = 0; i < NX; ++i) {
for (int j = 0; j < NY; ++j) {
tab[i][j] = rand() % 256;
}
}
for (int i = 0; i < NX; ++i) {
for (int j = 0; j < NY; ++j) {
printf("%d ", tab[i][j]);
}
printf("\n");
}
}
This diff is collapsed.