Skip to content
Snippets Groups Projects
Commit acdfccd7 authored by dario.genga's avatar dario.genga
Browse files

Add non finished ex5

Something is wrong from the second value of the reversed array.
parent de4b927b
Branches master
No related tags found
No related merge requests found
/* Author : Dario GENGA
* Date : 07.12.2021
* Description : Contrôle continue 1 - Exercice 5
*/
#include <stdio.h>
#include <stdlib.h>
#define ARRAY_LENGTH 6
void reverse(double *array_from, double *array_to, int index) {
if (index >= 0) {
array_to[ARRAY_LENGTH - index - 1] = array_from[index];
reverse(array_from, array_from, index - 1);
}
}
int main() {
double *array = malloc(sizeof(double) * ARRAY_LENGTH);
double *result = malloc(sizeof(double) * ARRAY_LENGTH);
for (int i = 0; i < ARRAY_LENGTH; i++) {
double value;
scanf("%lf", &value);
array[i] = value;
}
reverse(array, result, ARRAY_LENGTH - 1);
printf("\n");
for (int i = 0; i < ARRAY_LENGTH; i++) {
printf("%lf\n", result[i]);
}
free(array);
free(result);
return EXIT_SUCCESS;
}
LIB=-lm
CC=gcc -Wall -Wextra -pedantic -g
main: main.o
$(CC) $^ -fsanitize=address -fsanitize=leak -o $@ $(LIB)
main.o: main.c
$(CC) -c $< $(LIB)
clean:
rm -f *.o main
\ 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