diff --git a/myTP/.DS_Store b/myTP/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..cd31e5f093edd61b84de9210277591ee35a7d660 Binary files /dev/null and b/myTP/.DS_Store differ diff --git a/myTP/._.DS_Store b/myTP/._.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5a36534630e6619ad5b42b6c0523da6bef852bd5 Binary files /dev/null and b/myTP/._.DS_Store differ diff --git a/myTP/TP1/app b/myTP/TP1/app new file mode 100644 index 0000000000000000000000000000000000000000..1d4d2ac6f73e22f705d29285482db99c33ce176e Binary files /dev/null and b/myTP/TP1/app differ diff --git a/myTP/TP1/exercice1.c b/myTP/TP1/exercice1.c new file mode 100644 index 0000000000000000000000000000000000000000..959b4ac4badce594bc6158c95c8a803808cce63b --- /dev/null +++ b/myTP/TP1/exercice1.c @@ -0,0 +1,23 @@ +#include <stdio.h> + +int main(){ + int billet, billet50, billet20,billet10, billet100; + int piece5, piece2, piece1; + printf("Enter number less than 10000: "); + scanf("%d: ", &billet); + + + billet100 = billet / 100; + + billet50= billet100/50; + billet20= billet50/20; + billet10=billet20/10; + + piece5= billet10/5; + piece2=piece5/2; + piece1= piece2/1; + + + + printf("billets: %i,%i,%i,%i,%i,%i,%i\n", billet100, billet50, billet20, billet10, piece5,piece2,piece1); +} \ No newline at end of file diff --git a/myTP/TP1/exercice4.c b/myTP/TP1/exercice4.c new file mode 100644 index 0000000000000000000000000000000000000000..feb491ec7dc039dbfcd228367693fdc678e95de3 --- /dev/null +++ b/myTP/TP1/exercice4.c @@ -0,0 +1,21 @@ +#include <stdio.h> + +int main(){ + + int a; + int b; + int temp; + printf("Entrez la valeur a: "); + scanf("%d",&a); + printf("Entrez la valeur b: "); + scanf("%d",&b); + printf("valeurs avant a : %i\nvaleur b avant : %i",a,b); + temp = a; + a=b; + b=temp; + + printf("\nvaleurs apres a :%d",a); + printf("\nvaleurs apres b :%d",b); + + +} \ No newline at end of file diff --git a/myTP/TP1/exo4 b/myTP/TP1/exo4 new file mode 100644 index 0000000000000000000000000000000000000000..0c3e537c110008ba68cf32dd5d71d1226fe1eb4f Binary files /dev/null and b/myTP/TP1/exo4 differ diff --git a/myTP/TP10/exo1 b/myTP/TP10/exo1 new file mode 100644 index 0000000000000000000000000000000000000000..e4a7c65e6712bbb830ca970d2f143908559da08d Binary files /dev/null and b/myTP/TP10/exo1 differ diff --git a/myTP/TP10/exo1.c b/myTP/TP10/exo1.c new file mode 100644 index 0000000000000000000000000000000000000000..40c3e44399015ee6cc5ab91d1f38dba49747b2f0 --- /dev/null +++ b/myTP/TP10/exo1.c @@ -0,0 +1,88 @@ +#include <stdio.h> +#include <stdlib.h> +#include <stdbool.h> +#include <math.h> +#include <string.h> + +#define TAILLE 8 + +char E[TAILLE][TAILLE]; + +typedef enum {empty,covered,queen}board_state; + +// typedef struct{ +// board_state board[SIZE_MAX][SIZE_MAX]; +// int width, height; +// } board_t; + +// fill board with queen covering given the position of the queen column, row +// return 0 in case of success, -1 otherwise (for example if queen is out of the board) +// int queen_covering(board_t *board, char line, int column){ + + + + + +// } + + + +// print the given board in the terminal +//void print_board(board_t board){ + + + + + + +int main(int argc, char **argv){ + // int raws; + // int coloumn; + // printf("Entrez la ligne de la reine: "); + // scanf("%s",&line); + // printf("Entrez la colonne de la reine"); + // scanf("%s",&coloumn); + // queen_covering() + // printf("Couverture de la reine:"); + // print_board(board_t board); + + // char *size = argv[1]; + // char *height = argv[2]; + + int rows, cols, i, j, k; + + /* Input rows and columns from user */ + printf("Enter number of rows: "); + scanf("%d", &rows); + printf("Enter number of columns: "); + scanf("%d", &cols); + + + k = 1; + + for(i=1; i<=rows; i++) + { + for(j=1; j<=cols; j++) + { + + printf(". "); + + // If k = 1 then k *= -1 => -1 + // If k = -1 then k *= -1 => 1 + k *= -1; + } + + if(cols % 2 == 0) + { + + k *= -1; + } + + printf("\n"); + printf("A"); + } + + return 0; +} + + diff --git a/myTP/TP10/exo2.c b/myTP/TP10/exo2.c new file mode 100644 index 0000000000000000000000000000000000000000..bf33506a630ac2b22cd2d631b65af8090c07e8ec --- /dev/null +++ b/myTP/TP10/exo2.c @@ -0,0 +1,82 @@ +#include <stdio.h> +#include <stdlib.h> + +#define SIZE_MAX 8 + +typedef enum {empty, covered, queen} board_state; + +typedef struct { + board_state board[SIZE_MAX][SIZE_MAX]; + int width, height; +} board_t; + +int queen_covering(board_t *board, char line, int column){ + + for (int ligne = 0; ligne < SIZE_MAX; ++ligne){ + + for (int colonne =0; colonne < SIZE_MAX; ++colonne){ + + if (ligne == line-65 && colonne == column) { + + board->board[ligne][colonne] = queen; + + }else if (ligne == line-65 || colonne == column || abs(line-65-ligne)==abs(column-colonne)){ + + board->board[ligne][colonne] = covered; + + }else { + board->board[ligne][colonne] = empty; + } + + + } + } +} + +void print_board(board_t board) { + char index_h = 'H'; + int index_w = 0; + for(int i = 0; i < SIZE_MAX +1; ++i) { + printf("\n"); + for (int j =0; j < SIZE_MAX; ++j) { + if(j == 0) { + + if (i == SIZE_MAX){ + printf(" "); + }else { + printf("%c ", index_h); + } + } + if(i == SIZE_MAX) { + if (j != 0) { + printf("%d ", j); + }else { + printf(" "); + } + }else { + switch(board.board[i][j]) { + case covered: + printf("* "); + break; + case empty: + printf(". "); + break; + case queen: + printf("R "); + break; + } + } + + + } + --index_h; + } + printf("%d\n", SIZE_MAX); +} + +int main() { + + board_t board; + queen_covering(&board, 'C', 2); + print_board(board); +} \ No newline at end of file diff --git a/myTP/TP11/exo1 b/myTP/TP11/exo1 new file mode 100644 index 0000000000000000000000000000000000000000..921ae220acbebe0ffdff7fa766e956d95862d378 Binary files /dev/null and b/myTP/TP11/exo1 differ diff --git a/myTP/TP11/exo1.c b/myTP/TP11/exo1.c new file mode 100644 index 0000000000000000000000000000000000000000..eba87144cc0721958e31ddfdaabdb2da42125a84 --- /dev/null +++ b/myTP/TP11/exo1.c @@ -0,0 +1,76 @@ +#include <stdio.h> +#include <stdlib.h> +#include <stdbool.h> +#include <math.h> +#include <string.h> +#include <time.h> + + + +void ArrayFill( int tab[],int size){ + + for (unsigned i = 0; i < size; ++i) + { + + tab[i] += i ; + printf("p[%u] = %d\n", i, tab[i]); + } + + printf("\n"); + +} + +void Display( int tab[],int size){ + + for (unsigned i = 0; i < size; ++i) + { + printf("p[%u] = %d\n", i, tab[i]); + } + + printf("\n"); + +} + + + + +int *randomize2(int *tab, int size) { + for (int i = size-1 ; i >= 0; --i){ + // generate Random number + int n_random = rand() % size; + + // swap last element to + int temp = tab[i]; + tab[i] = tab[n_random]; + tab[n_random] = temp; + } + + return tab; + +} + + +int main(void) +{ + srand(time(0)); + + + int size=10; + //printf(" Entrez la valeur de size : "); + //scanf("%d",&size); + + int *tab = malloc(size *sizeof(int)); + + // randomize(tab,size); + ArrayFill(tab,size); + randomize2(tab,size); + Display(tab,size); + + free(tab); + return 0; +} + + + + + diff --git a/myTP/TP11/exo1.dSYM/Contents/Info.plist b/myTP/TP11/exo1.dSYM/Contents/Info.plist new file mode 100644 index 0000000000000000000000000000000000000000..ea858782144d29f3d6a4a740f9536fd4f66f6feb --- /dev/null +++ b/myTP/TP11/exo1.dSYM/Contents/Info.plist @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> + <dict> + <key>CFBundleDevelopmentRegion</key> + <string>English</string> + <key>CFBundleIdentifier</key> + <string>com.apple.xcode.dsym.exo1</string> + <key>CFBundleInfoDictionaryVersion</key> + <string>6.0</string> + <key>CFBundlePackageType</key> + <string>dSYM</string> + <key>CFBundleSignature</key> + <string>????</string> + <key>CFBundleShortVersionString</key> + <string>1.0</string> + <key>CFBundleVersion</key> + <string>1</string> + </dict> +</plist> diff --git a/myTP/TP11/exo1.dSYM/Contents/Resources/DWARF/exo1 b/myTP/TP11/exo1.dSYM/Contents/Resources/DWARF/exo1 new file mode 100644 index 0000000000000000000000000000000000000000..915531298d328044ef9816cfec1cc53112b11f7e Binary files /dev/null and b/myTP/TP11/exo1.dSYM/Contents/Resources/DWARF/exo1 differ diff --git a/myTP/TP11/exo1.dSYM/Contents/Resources/Relocations/aarch64/exo1.yml b/myTP/TP11/exo1.dSYM/Contents/Resources/Relocations/aarch64/exo1.yml new file mode 100644 index 0000000000000000000000000000000000000000..26d74f767995ae22cff370d6a50a1185f40409c2 --- /dev/null +++ b/myTP/TP11/exo1.dSYM/Contents/Resources/Relocations/aarch64/exo1.yml @@ -0,0 +1,13 @@ +--- +triple: 'arm64-apple-darwin' +binary-path: exo1 +relocations: + - { offsetInCU: 0xDA, offset: 0xDA, size: 0x8, addend: 0x0, symName: _ArrayFill, symObjAddr: 0x0, symBinAddr: 0x100003C10, symSize: 0xB4 } + - { offsetInCU: 0x9F, offset: 0x9F, size: 0x8, addend: 0x0, symName: _main, symObjAddr: 0x218, symBinAddr: 0x100003E28, symSize: 0x64 } + - { offsetInCU: 0xEC, offset: 0xEC, size: 0x8, addend: 0x0, symName: _randomize2, symObjAddr: 0x130, symBinAddr: 0x100003D40, symSize: 0xE8 } + - { offsetInCU: 0xF4, offset: 0xF4, size: 0x8, addend: 0x0, symName: _main, symObjAddr: 0x218, symBinAddr: 0x100003E28, symSize: 0x64 } + - { offsetInCU: 0x177, offset: 0x177, size: 0x8, addend: 0x0, symName: _Display, symObjAddr: 0xB4, symBinAddr: 0x100003CC4, symSize: 0x7C } + - { offsetInCU: 0x17F, offset: 0x17F, size: 0x8, addend: 0x0, symName: _randomize2, symObjAddr: 0x130, symBinAddr: 0x100003D40, symSize: 0xE8 } + - { offsetInCU: 0x1D7, offset: 0x1D7, size: 0x8, addend: 0x0, symName: _ArrayFill, symObjAddr: 0x0, symBinAddr: 0x100003C10, symSize: 0xB4 } + - { offsetInCU: 0x1DF, offset: 0x1DF, size: 0x8, addend: 0x0, symName: _Display, symObjAddr: 0xB4, symBinAddr: 0x100003CC4, symSize: 0x7C } +... diff --git a/myTP/TP11/exo2 b/myTP/TP11/exo2 new file mode 100644 index 0000000000000000000000000000000000000000..6ee4c19533c866a88ec2f925837b7b2a2290ea68 Binary files /dev/null and b/myTP/TP11/exo2 differ diff --git a/myTP/TP11/exo2.c b/myTP/TP11/exo2.c new file mode 100644 index 0000000000000000000000000000000000000000..2c2be15e4d5fa86d2afe0f221a936aefda77a97a --- /dev/null +++ b/myTP/TP11/exo2.c @@ -0,0 +1,20 @@ +#include <stdio.h> +void foo(int a) { +a += 3; +} +void bar(int *a) { +*a += 3; +} +void baz(int *a) { +a += 3; +} +int main() { +int a = 5; +printf("%i\n", a); +foo(a); +printf("%i\n", a); +bar(&a); +printf("%i\n", a); +baz(&a); +printf("%i\n", a); +} \ No newline at end of file diff --git a/myTP/TP11/exo2.dSYM/Contents/Info.plist b/myTP/TP11/exo2.dSYM/Contents/Info.plist new file mode 100644 index 0000000000000000000000000000000000000000..b61d5bcbdf395ceefeeeca089a5a20ef18d6564d --- /dev/null +++ b/myTP/TP11/exo2.dSYM/Contents/Info.plist @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> + <dict> + <key>CFBundleDevelopmentRegion</key> + <string>English</string> + <key>CFBundleIdentifier</key> + <string>com.apple.xcode.dsym.exo2</string> + <key>CFBundleInfoDictionaryVersion</key> + <string>6.0</string> + <key>CFBundlePackageType</key> + <string>dSYM</string> + <key>CFBundleSignature</key> + <string>????</string> + <key>CFBundleShortVersionString</key> + <string>1.0</string> + <key>CFBundleVersion</key> + <string>1</string> + </dict> +</plist> diff --git a/myTP/TP11/exo2.dSYM/Contents/Resources/DWARF/exo2 b/myTP/TP11/exo2.dSYM/Contents/Resources/DWARF/exo2 new file mode 100644 index 0000000000000000000000000000000000000000..fbc902e906ce4ad5e9efb17e91892f7577eff6bc Binary files /dev/null and b/myTP/TP11/exo2.dSYM/Contents/Resources/DWARF/exo2 differ diff --git a/myTP/TP11/exo2.dSYM/Contents/Resources/Relocations/aarch64/exo2.yml b/myTP/TP11/exo2.dSYM/Contents/Resources/Relocations/aarch64/exo2.yml new file mode 100644 index 0000000000000000000000000000000000000000..b665220683f9b5c79d00fc7c71f437d016aa4cea --- /dev/null +++ b/myTP/TP11/exo2.dSYM/Contents/Resources/Relocations/aarch64/exo2.yml @@ -0,0 +1,11 @@ +--- +triple: 'arm64-apple-darwin' +binary-path: exo2 +relocations: + - { offsetInCU: 0x26, offset: 0x26, size: 0x8, addend: 0x0, symName: _foo, symObjAddr: 0x0, symBinAddr: 0x1000037A0, symSize: 0x1C } + - { offsetInCU: 0x3B, offset: 0x3B, size: 0x8, addend: 0x0, symName: _.str, symObjAddr: 0x5A0, symBinAddr: 0x100003DC0, symSize: 0x0 } + - { offsetInCU: 0x5E, offset: 0x5E, size: 0x8, addend: 0x0, symName: _foo, symObjAddr: 0x0, symBinAddr: 0x1000037A0, symSize: 0x1C } + - { offsetInCU: 0x82, offset: 0x82, size: 0x8, addend: 0x0, symName: _bar, symObjAddr: 0x1C, symBinAddr: 0x1000037BC, symSize: 0x90 } + - { offsetInCU: 0xA6, offset: 0xA6, size: 0x8, addend: 0x0, symName: _baz, symObjAddr: 0xAC, symBinAddr: 0x10000384C, symSize: 0x1C } + - { offsetInCU: 0xCA, offset: 0xCA, size: 0x8, addend: 0x0, symName: _main, symObjAddr: 0xC8, symBinAddr: 0x100003868, symSize: 0x440 } +... diff --git a/myTP/TP11/test.c b/myTP/TP11/test.c new file mode 100644 index 0000000000000000000000000000000000000000..621818da18167d5781e041478643fc15db7fd5a9 --- /dev/null +++ b/myTP/TP11/test.c @@ -0,0 +1,30 @@ +#include <stdio.h> +#include <math.h> +#include <stdlib.h> + + + + +void shuffle(int *array, int n) { + int i, j, tmp; + + for (i = n - 1; i > 0; i--) { + j = rand()% (i+1); + tmp = array[j]; + array[j] = array[i]; + array[i] = tmp; + } +} +int main(void) +{ + + int i = 0; + int numbers[10]; + for (i = 0; i < 10; i++) + numbers[i]= i; + shuffle(numbers, 10); + printf("\nArray after shuffling is: \n"); + for ( i = 0; i < 10; i++) + printf("p[%u] = %d\n", i, numbers[i]); + return 0; +} \ No newline at end of file diff --git a/myTP/TP12/annuary b/myTP/TP12/annuary new file mode 100644 index 0000000000000000000000000000000000000000..236d80b09b28ebf74be3b3ea6f745fa2681ff364 Binary files /dev/null and b/myTP/TP12/annuary differ diff --git a/myTP/TP12/exo1 b/myTP/TP12/exo1 new file mode 100644 index 0000000000000000000000000000000000000000..43eef9692d74500af7726f8daaee835b0fd42796 Binary files /dev/null and b/myTP/TP12/exo1 differ diff --git a/myTP/TP12/exo1.c b/myTP/TP12/exo1.c new file mode 100644 index 0000000000000000000000000000000000000000..af97c86d6c4a23ee9430e121d9109e83cf3ffffd --- /dev/null +++ b/myTP/TP12/exo1.c @@ -0,0 +1,267 @@ +#include <stdio.h> +#include <stdlib.h> +#include <stdbool.h> +#include <math.h> +#include <string.h> +#include <time.h> + +#define INIT_DIT_CAPACITY 5 + + +typedef struct { +int day, month, year; +} date_t; + + +typedef struct { +char name[40]; +char surname[40]; +date_t birthday; +int phone_number; +} person_t; + +typedef struct { +int size; +int capacity; +person_t *content; +} directory_t; + + +// Prints a person record with the format "Name Surname, day-month-year, phone number" +// Parameter : p - the person +void person_print(person_t p){ + + printf("%s %s, %d/%d/%d,%d \n",p.name,p.surname,p.birthday.day,p.birthday.month,p.birthday.year,p.phone_number); + + +} +// Creates a new directory with size 0 and capacity INIT_DIT_CAPACITY + +void dir_init(directory_t *dir){ + + dir->size=0; + dir->capacity= INIT_DIT_CAPACITY; + + if (dir->content == NULL) { + dir->content = malloc(sizeof(person_t) * dir->capacity); + } else { + dir->content = realloc(dir->content, sizeof(person_t) * dir->capacity); + } + +} + +directory_t dir_create(){ + + directory_t newDirectory; + newDirectory.content = NULL; + + dir_init(&newDirectory); + + return newDirectory; + +} +// Free the memory of the directory, set size and capacity to 0 and content to NULL +// Parameter : dir - the directory +void dir_free(directory_t *dir){ + + dir->capacity=0; + dir->size=0; + free(dir->content); +} +// Prints the content of a directory each line with the format "[n] person" +// with n being the position in the directory +// Parameters : dir - the directory + +void dir_print(directory_t *dir,int n){ + + + if(n==-1){ + for (int i = 0; i < dir->size; i++) + { + person_t t = dir->content[i]; + printf("[%d] ",i); + person_print(t); + } + }else { + + person_t t = dir->content[n]; + printf("[%d] ",n); + person_print(t); + + } + + + +} + + +// Erase a directory by setting its size to 0, but letting its capacity untouched +// Parameter : dir - the directory +void dir_erase(directory_t *dir){ + + dir->size=0; + +} + +// Add a person to the directory if its capacity is not reached and increase its size +// If the capacity is reached, attempt to increase the capacity before adding the person +// Parameters : dir - the directory, p - the person +// Returns : 0 if success, 1 otherwise +int dir_add_entry(directory_t *dir, person_t p){ + + if (dir->size >= dir->capacity) { + person_t *new_p = realloc(dir->content, (dir->size + 1) * sizeof(person_t)); + if (new_p == NULL) { + return 1; + } + dir->content = new_p; + dir->capacity += 1; + } + + dir->content[dir->size] = p; + dir->size++; + + return 0; + +} + +// Parameter : dir - the direcory +// Returns : 0 if success, 1 otherwise +int dir_fill(directory_t *dir){ + +dir_init(dir); + +if(dir_add_entry(dir, (person_t){"Jean", "Paul", (date_t){18, 12, 1967}, 12346890})) return 1; +if(dir_add_entry(dir, (person_t){"Arthur", "Rimbaud", (date_t){1, 1, 2002}, 73645})) return 1; +if(dir_add_entry(dir, (person_t){"Paul", "Albuquerque", (date_t){23, 6, 1902}, 28736474})) return 1; +if(dir_add_entry(dir, (person_t){"Christophe", "Charpilloz", (date_t){11, 4, 2008}, 76253})) return 1; +if(dir_add_entry(dir, (person_t){"Emily", "Dickinson", (date_t){19, 8, 1950}, 636363})) return 1; +if(dir_add_entry(dir, (person_t){"Ada", "Lovelace", (date_t){12, 12, 2022}, 12345})) return 1; +if(dir_add_entry(dir, (person_t){"Qwertz", "Uiop", (date_t){1, 1, 562}, 67879})) return 1; +printf("current dir size : %lu \n", dir->size); + +} + + +// Delete the entry at position n of the directory if n is smaller than +// the size of the directory, does nothing otherwise +// Parameters : dir - the direcory, n - the position +void dir_delete_entry(directory_t *dir, int n){ + if(n < dir->size){ + + for (int i = 0; i< dir->size-1; i++) + { + dir->content[i]=dir->content[i+1]; + } + + dir->size--; + + } + + printf("Contact removed from Annuary.\n"); + +} +// Searches for an entry with a given surname +// Parameters : dir - the directory, surname - the surname to search +// Returns : the index of a matching entry, a negative number if no match is found +int dir_search_surname(directory_t* dir, char* surname){ + + for (int i = 0; i < dir->size; i++) + { + person_t p = dir->content[i]; + if (strcmp(surname, dir->content[i].surname) == 0) { + return i; + } + } + return -1; + +} + +int main(){ + + + directory_t directory = dir_create(); + + dir_fill(&directory); + + + printf("Available commands : add, del, show, search, quit,\n"); + char command[255]=" "; + while(strcmp(command,"quit")!=0){ + printf("> "); + scanf("%s", &command); + + + if(strcmp(command,"add")==0){ + person_t new_p; + + printf("Enter the name: "); + scanf("%s",&new_p.name); + printf("Enter the surname: "); + scanf("%s",&new_p.surname); + printf("Enter the day of birth: "); + scanf("%s",&new_p.birthday.day); + printf("Enter the day of birth: "); + scanf("%s",&new_p.birthday.day); + printf("Enter the month of birth: "); + scanf("%s",&new_p.birthday.month); + printf("Enter the year of birth: "); + scanf("%s",&new_p.birthday.year); + printf("Enter the phone number: "); + scanf("%s",&new_p.phone_number); + + + dir_add_entry(&directory,new_p); + + }else if(strcmp(command,"del")==0){ + int index; + + printf("Enter index to remove: "); + scanf("%s",&index); + dir_delete_entry(&directory,index); + + printf("Contact removed from Annuary.\n"); + + }else if(strcmp(command,"show")==0){ + + char options[40]=""; + printf("enter the name to show or all if you want to show entire directory: \n" ); + scanf("%s",options); + int index=-1; + + if (strcmp(options,"all")==0){ + + dir_print(&directory,index); + }else { + + index= dir_search_surname(&directory,options); + dir_print(&directory,index); + + }; + + + }else if(strcmp(command,"search")==0){ + int index=-1; + char Surname[255]; + printf(" Enter Surname: "); + scanf("%s",&Surname); + + dir_search_surname(&directory,Surname); + + if(index>=0){ + + printf("The Surname index is : %d\n",index); + }else{ + + printf("The Surname index doesn't exist"); + } + } + else if(strcmp(command,"quit")==0){ + dir_erase(&directory); + + printf("Directory erased"); + } + } + dir_free(&directory); + +} \ No newline at end of file diff --git a/myTP/TP12/test.c b/myTP/TP12/test.c new file mode 100644 index 0000000000000000000000000000000000000000..82ee206d5b1bf7e44e1c8247c22224178b3f6014 --- /dev/null +++ b/myTP/TP12/test.c @@ -0,0 +1,29 @@ + + +#include <stdio.h> +#include <stdlib.h> +#include <stdbool.h> + +typedef struct { + char *name; + int thread_id; + bool is_valid; +}T_THREAD; +void print_struct_elements(T_THREAD *T) { + printf("\nContents of a structure %s are:\n", T->name); + printf("thread_id: %d\n",T->thread_id); + printf("is_valid: %d\n", T->is_valid); +} + +int main(void) { + + T_THREAD T1 = {"T1", 123, 1}; + T_THREAD T2 = {"T2", 456, 0}; + + print_struct_elements(&T1); + print_struct_elements(&T2); + + return 0; +} + + diff --git a/myTP/TP13/exo1 b/myTP/TP13/exo1 new file mode 100644 index 0000000000000000000000000000000000000000..6ed247a3f99a740a556b9668eca78555510f9659 Binary files /dev/null and b/myTP/TP13/exo1 differ diff --git a/myTP/TP13/exo1.c b/myTP/TP13/exo1.c new file mode 100644 index 0000000000000000000000000000000000000000..762ef751095f2606161b8dc41f7c4b60577ca1cf --- /dev/null +++ b/myTP/TP13/exo1.c @@ -0,0 +1,57 @@ + +/* + * C Program to Reverse the String using Recursion + */ +#include <stdio.h> +#include <string.h> +void reverse_print(char* str); +void reverse(char [], int, int); +int count(char* str, char c); +int main() +{ + char str1[20]= "salut"; + int size; + + char* str = "Salut les amis\n"; + + size = strlen(str1); + reverse(str1, 0, size - 1); + + reverse_print(str); + printf("Number: %d\n",count(str,'a')); + + + printf("The string after reversing is: %s\n", str1); + return 0; +} + +void reverse_print(char* str){ + + if(*str){ + + reverse_print(str+1); + printf("%c",*str); + } +} + +int count(char* str, char c){ + + if(*str!='\0'){ + return count(str+1,c)+(*str==c); + } + + +} + +void reverse(char str1[], int index, int size) +{ + char temp; + temp = str1[index]; + str1[index] = str1[size - index]; + str1[size - index] = temp; + if (index == size / 2) + { + return; + } + reverse(str1, index + 1, size); +} \ No newline at end of file diff --git a/myTP/TP2/exo1 b/myTP/TP2/exo1 new file mode 100644 index 0000000000000000000000000000000000000000..a88882201331b70d22c726983eea8649a5df4440 Binary files /dev/null and b/myTP/TP2/exo1 differ diff --git a/myTP/TP2/exo1.c b/myTP/TP2/exo1.c new file mode 100644 index 0000000000000000000000000000000000000000..1352e7a22176f77e3064727cc3a1129dae0a18e7 --- /dev/null +++ b/myTP/TP2/exo1.c @@ -0,0 +1,18 @@ +#include <stdio.h> +#include <math.h> + + + +void main(){ + float rayon,puissance; + float perimeter; + float area; + printf("Entrez le rayon du cercle:"); + scanf("%f",&rayon); + puissance = rayon*rayon; + perimeter = 2 * 3.14 * rayon; + area = 3.14 * puissance; + + printf("le perimètre est: %f \n l'aire est: %f",perimeter,area); + +} \ No newline at end of file diff --git a/myTP/TP2/exo2 b/myTP/TP2/exo2 new file mode 100644 index 0000000000000000000000000000000000000000..e58099dc501845b006816a7fd44e5494ef9ff6d7 Binary files /dev/null and b/myTP/TP2/exo2 differ diff --git a/myTP/TP2/exo2.c b/myTP/TP2/exo2.c new file mode 100644 index 0000000000000000000000000000000000000000..7fd0ce2b45d090013c9d4b0403b78058fb5197ef --- /dev/null +++ b/myTP/TP2/exo2.c @@ -0,0 +1,20 @@ +#include <stdio.h> +#include <math.h> + + + +int main(){ + + float nombre1,nombre2,result; + printf("Entrez le nombre 1"); + scanf("%f",&nombre1); + printf("Entrez le nombre 2"); + scanf("%f",&nombre2); + + result=nombre1*nombre2; + + + printf("le résultat de la multiplication %f",result); + + +} \ No newline at end of file diff --git a/myTP/TP2/exo3 b/myTP/TP2/exo3 new file mode 100644 index 0000000000000000000000000000000000000000..bef4517f9728c7881e0984877c30ecadb402cfb6 Binary files /dev/null and b/myTP/TP2/exo3 differ diff --git a/myTP/TP2/exo3.c b/myTP/TP2/exo3.c new file mode 100644 index 0000000000000000000000000000000000000000..cc89d093edef2b29a4b5d1af3a1ca4759f13317c --- /dev/null +++ b/myTP/TP2/exo3.c @@ -0,0 +1,34 @@ +#include <stdio.h> +#include <math.h> + + + + +int main(){ + + int n =10,p =4; + long q =2; + float x =1.75; + + int final = n; + + printf("n+q: %d\n", final); + printf("n+x: %f\n", n+x); + printf("n mod p + q: %d\n", n%p + q); + printf("n<p: %d\n", n<p); + printf("n>=p: %d\n", n>=p); + printf("n>q: %d\n", n>p); + printf("q + 3 * (n > p): %d\n", q + 3 * (n > p)); + printf("q && n: %d\n",q && n); + printf("(q-2)&& (n-10): %d\n", (q-2)&&(n-10)); + printf("x * (q==2) %d\n", x * (q==2)); + printf("x * (q=5) %d\n", x * (q=5)); + + + + + + + + +} \ No newline at end of file diff --git a/myTP/TP3/exo1 b/myTP/TP3/exo1 new file mode 100644 index 0000000000000000000000000000000000000000..a1d2fb18efdb1017ca7b8d1f89a85d78c38f1c53 Binary files /dev/null and b/myTP/TP3/exo1 differ diff --git a/myTP/TP3/exo1.c b/myTP/TP3/exo1.c new file mode 100644 index 0000000000000000000000000000000000000000..e30bcd6d4f3a9159ceff0248525e0ba6d325f40f --- /dev/null +++ b/myTP/TP3/exo1.c @@ -0,0 +1,37 @@ +#include <stdio.h> +#include <stdlib.h> +#include <time.h> + +void main(){ + int max_number; + int user_number=0; + int random_number; + int counter=0; + + printf("Entrez le nombre maximum:"); + scanf("%d",&max_number); + srand(time(NULL)); + while(random_number> max_number|| random_number<0){random_number= rand(); + } + printf("nombre généré : %d\n",random_number); + printf("Entrez le nombre désirer\n"); + scanf("%d",&user_number); + while(user_number!=random_number){ + + if(user_number<0 || user_number>max_number ){ + printf("Erreur, Entrez un nombre supérieur à 0 et inférieur au nombre maximum\n"); + printf("Entrez le nombre désirer : "); + scanf("%d",&user_number); + } + if(user_number< random_number){ + printf("plus grand\n"); + counter++; + }else{ + printf("plus petit\n"); + counter++; + } + printf("Entrez une nouvelle valeur: "); + scanf( "%d",&user_number); + } + printf("Voici le nombre d'essai effectués: %d",counter); +} \ No newline at end of file diff --git a/myTP/TP4/exo1 b/myTP/TP4/exo1 new file mode 100644 index 0000000000000000000000000000000000000000..50b0e247a056f587f489ec35c88e84ef44f631c7 Binary files /dev/null and b/myTP/TP4/exo1 differ diff --git a/myTP/TP4/exo1.c b/myTP/TP4/exo1.c new file mode 100644 index 0000000000000000000000000000000000000000..5b9a3724403029c2a854d8ed4cb6bdfc20a66b46 --- /dev/null +++ b/myTP/TP4/exo1.c @@ -0,0 +1,37 @@ +#include <stdio.h> +#include <stdlib.h> +#include <time.h> + +void main(){ + + + int year; + + printf("Entrez une année:"); + scanf("%d",&year); + + if (year % 4 ==0){ + + if (year % 100 == 0 ){ + + + if(year % 400 ==0){ + + printf("l'année: %d est bisextile",year); + + }else printf("l'année n'est pas bisextile"); + + }else printf("l'année: %d est bisextile",year); + + }else { + + printf("l'année n'est pas bisextile"); + } + + + + + + + +} \ No newline at end of file diff --git a/myTP/TP4/exo2 b/myTP/TP4/exo2 new file mode 100644 index 0000000000000000000000000000000000000000..d23f26c38c622e96d70df995f9d1819f64adc8df Binary files /dev/null and b/myTP/TP4/exo2 differ diff --git a/myTP/TP4/exo2.c b/myTP/TP4/exo2.c new file mode 100644 index 0000000000000000000000000000000000000000..39733463573eb654a6a552cc40e5d886bf98988a --- /dev/null +++ b/myTP/TP4/exo2.c @@ -0,0 +1,28 @@ +#include <stdio.h> +#include <stdlib.h> +#include <math.h> + +void main(){ + + int P_number; + + printf("Entrez un nombre:"); + scanf("%d",&P_number); + + for(int i=0; i<sqrt(P_number); i++){ + + if (P_number % 2 ==0){ + printf("n'est pas un premier"); + break; + }else{ + printf("est un premier"); + + break; + } + + + } + + + +} \ No newline at end of file diff --git a/myTP/TP5/exo1 b/myTP/TP5/exo1 new file mode 100644 index 0000000000000000000000000000000000000000..cee3f98e0618f350037c376aadad5f5107df80e0 Binary files /dev/null and b/myTP/TP5/exo1 differ diff --git a/myTP/TP5/exo1.c b/myTP/TP5/exo1.c new file mode 100644 index 0000000000000000000000000000000000000000..547c1adf28e23410e4dcc4a684b2dd65d31a359a --- /dev/null +++ b/myTP/TP5/exo1.c @@ -0,0 +1,84 @@ +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <stdbool.h> + + +bool is_prime(int n){ + + for(int i=0; i<sqrt(n); i++){ + + if (n % 2 ==0){ + return false; + break; + }else{ + return true; + break; + } + } + return true; + +} + +void swap(int* a, int* b){ + + int temp ; + temp = *a; + *a = *b; + *b = temp; + +} + + + + +int ppcm(int a, int b){ + + int ppcm; + + + + if(i% a==0 && i%a ==0 ){ + + ppcm = i; + }for (int i=a*b;i>=a;i--){ + } + + return ppcm; +} + + + + + +int pgcd(int a, int b){ + + int pgcd; + + for (int i=1; i<= a && i <= b;i++){ + + if (a % i == 0 && b % i == 0){ + pgcd = i; + } + } + return pgcd; +} + + + + +int main(){ + + + int a = 12; + int b = 60; + printf("IsPrime : %d\n",is_prime(6)); + swap(&a,&b); + + printf("Valeur de a : %d et valeur de b: %d\n",a,b); + printf("le pgcd de %d et %d est: %d\n",a,b,pgcd(a,b)); + printf("le ppcm de %d et %d est: %d ",a,b,ppcm(a,b)); + + return 0; + +} \ No newline at end of file diff --git a/myTP/TP6/exo1 b/myTP/TP6/exo1 new file mode 100644 index 0000000000000000000000000000000000000000..0d1098989113a5394f0a2c2645ee1a52b5bb9600 Binary files /dev/null and b/myTP/TP6/exo1 differ diff --git a/myTP/TP6/exo1.c b/myTP/TP6/exo1.c new file mode 100644 index 0000000000000000000000000000000000000000..d5c4e1b8131777c6f29203c5febda890ffa146bd --- /dev/null +++ b/myTP/TP6/exo1.c @@ -0,0 +1,55 @@ +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <stdbool.h> + +double Function_value (double x){ + + //double function = 3*pow(x,3)+ pow(x,2) - 27; + double function = sin(x); + + + return function; + +} + +float sign(double x){ + + if(x > 0){ + return 1; + }else if (x<=0){ + return -1; + } + +} + +int study_function(double epsilon,double low, double high){ + + double counter=0; + + while (low<high){ + + low +=epsilon; + double now = sign(Function_value(low)); + double previous = sign(Function_value(low-epsilon)); + + if( previous !=now ) counter++; + } + + printf("nombre de changement: %f\n", counter); + + return counter; +} + + +int main(){ + + double espilon = 0.1; + double low = -3.5; + double high = 3.5; + + study_function(espilon,low,high); + + return 0; +} + diff --git a/myTP/TP6/tp_06_encore_fonctions.pdf b/myTP/TP6/tp_06_encore_fonctions.pdf new file mode 100644 index 0000000000000000000000000000000000000000..25c5b64da51faf75e88a4df74ab01666ba2412f9 Binary files /dev/null and b/myTP/TP6/tp_06_encore_fonctions.pdf differ diff --git a/myTP/TP7/exo1 b/myTP/TP7/exo1 new file mode 100644 index 0000000000000000000000000000000000000000..f68e94be696a513b861863a48d45d10250907faa Binary files /dev/null and b/myTP/TP7/exo1 differ diff --git a/myTP/TP7/exo1.c b/myTP/TP7/exo1.c new file mode 100644 index 0000000000000000000000000000000000000000..c43c033003b951a6714288ce7ff78f5a597847c6 --- /dev/null +++ b/myTP/TP7/exo1.c @@ -0,0 +1,63 @@ +#include <stdio.h> +#include <stdlib.h> +#include <time.h> + +#define SIZE 10 + +int main(){ + + srand(time(NULL)); + double tab[SIZE]; + + //génère une liste de 10 élements aléatoire + for (int i=0; i < SIZE; ++i){ + tab[i] = rand()/(double)RAND_MAX; + //printf("%d\n",tab[i]); + } + + + + // génère une liste de 9 éléments aléatoire + for (int i = 0 ; i< SIZE -1 ; ++i){ + tab[i] = rand() / (double)RAND_MAX; + //printf("%d\n",tab[i]); + } + + //tri la liste avec la valeur la plus petite + for (int i = 0; i < SIZE - 1; ++i) { + double min = tab[i]; + int ind_min = i; + for (int j = i + 1; j < SIZE; ++j) { + if (min > tab[j]) { + ind_min = j; + min = tab[j]; + } + } + + + + + + double tmp = tab[i]; + tab[i] = tab[ind_min]; + tab[ind_min] = tmp; + + printf("Test :%f\n",tab[ind_min]); + } + + + + for (int i = 0; i < SIZE; ++i) { + printf("%f ", tab[i]); + } + printf("\n"); + + + for (int i = 0; i < SIZE - 1; ++i) { + if (tab[i] > tab[i + 1]) { + return EXIT_FAILURE; + } + } + return EXIT_SUCCESS; + +} diff --git a/myTP/TP8/algorithmique-programmation-soir-2023-2024-public.code-workspace b/myTP/TP8/algorithmique-programmation-soir-2023-2024-public.code-workspace new file mode 100644 index 0000000000000000000000000000000000000000..ca32e10c951d199e7521ea7b908992e61795d741 --- /dev/null +++ b/myTP/TP8/algorithmique-programmation-soir-2023-2024-public.code-workspace @@ -0,0 +1,12 @@ +{ + "folders": [ + { + "path": ".." + } + ], + "settings": { + "files.associations": { + "COURS.C": "cpp" + } + } +} \ No newline at end of file diff --git a/myTP/TP8/exo1 b/myTP/TP8/exo1 new file mode 100644 index 0000000000000000000000000000000000000000..4c8fae46bc2a47ba50707b66e48c54844348134c Binary files /dev/null and b/myTP/TP8/exo1 differ diff --git a/myTP/TP8/exo1.c b/myTP/TP8/exo1.c new file mode 100644 index 0000000000000000000000000000000000000000..e39896ba806668ea75b2d47e58a5fcd820c3645b --- /dev/null +++ b/myTP/TP8/exo1.c @@ -0,0 +1,53 @@ +#include <stdio.h> +#include <stdlib.h> +#include <time.h> +#include <stdbool.h> +#include <math.h> + + +#define N 10 + + + +void eratosthene( int n, bool tab[]){ + + + int i,j; + for(i = 2; i <= N; i++) + { + if(tab[i] ==true) + { + for(j = pow(i, 2); j <= N; j +=i) + { + tab[j] = false; + } + } + } + + +} + + + +int main(){ + + bool tab[N]; + int result; + + for (int i = 0; i <= N ; i++) { + tab[i]=true; + } + + eratosthene(N,tab); + + for (int i =2 ; i <= N-1 ; i++) { + if(tab[i]==1){ + printf("%d ",i); + } + } + + + return 0; + + +} diff --git a/myTP/TP8/exo2.c b/myTP/TP8/exo2.c new file mode 100644 index 0000000000000000000000000000000000000000..f1fd6583a2d4363fecb7216fca6958efbf726c84 --- /dev/null +++ b/myTP/TP8/exo2.c @@ -0,0 +1,33 @@ + +int main() +{ + int num[N], i, j; + int limit = sqrt(N); + + for(i = 0; i < N; i++) + num[i] = i + 1; + + for(i = 1; i <= limit; i++) + { + if(num[i] != 0) + { + for(j = pow(num[i], 2); j <= N; j = j + num[i]) + { + num[j - 1] = 0; + } + } + + } + + printf("Sieve of Eratosthenes Method\n"); + printf("To find Prime numbers from 2 to %d\n\n", N); + for(i = 1; i < N; i++) + { + if(num[i] != 0) + printf("%d\t", num[i]); + } + + printf("\n"); + + return 0; +} diff --git a/myTP/TP9/exo1 b/myTP/TP9/exo1 new file mode 100644 index 0000000000000000000000000000000000000000..cca4d4709d05d6dbbd9b1974386d5b7ac565e112 Binary files /dev/null and b/myTP/TP9/exo1 differ diff --git a/myTP/TP9/exo1.c b/myTP/TP9/exo1.c new file mode 100644 index 0000000000000000000000000000000000000000..0442b1abf783e4ca80db6283944d2f8b4626b7d8 --- /dev/null +++ b/myTP/TP9/exo1.c @@ -0,0 +1,85 @@ +#include <stdio.h> +#include <stdlib.h> +#include <time.h> +#include <stdbool.h> +#include <math.h> +#include <string.h> + + +void sort (char str[]){ + char temp; + for(int i = 0; i <=strlen(str)-1 ; i++){ + + for ( int j = i+1; j < strlen(str); j++){ + + if(str[i]>str[j]){ + temp = str[i]; + str[i] = str[j]; + str[j] = temp; + } + } + } +} + +bool isanagram(char str1[], char str2[]){ + sort(str1); + sort(str2); + printf("test: %s \n",str1); + printf("test: %s \n",str2); + + if (!strcmp(str1,str2)){ + printf("YES"); + return true; + }else return false; +} + +void revert (char str1[]){ + + int temp; + + int max_right = strlen(str1)-2; + + for(int i = 0; i <max_right; i++){ + + temp = str1[max_right]; + str1[i] = str1[max_right]; + str1[max_right] = temp; + max_right--; + + } + + printf("%s",str1); + + char str2[60]; + strcpy(str2,str1); + + //printf("%s",str2); + + +} + +bool ispalindrome(char str1[], char str2[]){ + + + +} + +int main(int argc, char **argv){ + + char str1[] = "kayak"; + char str2[]= "mdr" ; + + //char *str1 = argv[1]; + //char *str2 = argv[2]; + //printf("%s",argv[0]); + //if (isanagram(str1,str2)) printf("Les deux chaines sont des anagrames"); + //else printf("Les deux chaines ne sont pas des anagrames"); + revert(str2); + + // sort(name); + // printf("%s",name); + // printf("char length : %d ",strlen(name)); + + return 0 ; + +} diff --git a/myTP/TP9/exo2.c b/myTP/TP9/exo2.c new file mode 100644 index 0000000000000000000000000000000000000000..4be614e69f4e39321ff78f3f1c792e01a38848b1 --- /dev/null +++ b/myTP/TP9/exo2.c @@ -0,0 +1,25 @@ +#include <stdio.h> +#include <stdlib.h> +#include <time.h> +#include <stdbool.h> +#include <math.h> +#include <string.h> + + +void revert (char str1[], char str2[]){ + +} + +bool ispalindrome(char str1[], char str2[]){ + + + +} + +int main(ar){ + + + + return 0 ; + +} \ No newline at end of file diff --git a/myTP/exo1 b/myTP/exo1 new file mode 100644 index 0000000000000000000000000000000000000000..09ab56864dd0ffe2c6c5ed95f0826c09f0c2a8f8 Binary files /dev/null and b/myTP/exo1 differ diff --git a/myTP/test.c b/myTP/test.c new file mode 100644 index 0000000000000000000000000000000000000000..4b3cc8b4e89858084b9c85154a56bcf537779d6e --- /dev/null +++ b/myTP/test.c @@ -0,0 +1,48 @@ + +#include <stdio.h> + + + + + +void recurse(int n){ + + + printf("%d", n%2); + + if(n/2!=0){ + recurse(n/2); + + }else { + printf("\n"); + } + +} + +int fibonacci( int i){ + + + + if(i>1){ + return printf("fibo: %u \n",fibonacci(i-1)+fibonacci(i-2)); + + } + return i; + + + + + +} + +int main(){ + + //recurse(13); + fibonacci(6); + + + return 0; + + + +} \ No newline at end of file