Skip to content

Commit

Permalink
16.5
Browse files Browse the repository at this point in the history
  • Loading branch information
cfouche3005 committed Jan 18, 2022
1 parent 61beb5d commit 2e12b06
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 21 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ project(ISENAlgoC C)
set(CMAKE_C_STANDARD 11)

add_executable(ISENAlgoC
TP7/ex2/TP7ex22.c )
TP7/ex2/TP7ex21.c )
16 changes: 7 additions & 9 deletions TP7/ex2/TP7ex21.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,22 @@ int main (int argc, char** argv) {
int* impair;
int taillepair = 0;
int tailleimpair = 0;

pair = malloc ((argc-1)*sizeof (int) ) ;
impair = malloc ((argc-1)*sizeof (int) ) ;
if (pair != NULL) {

if ((pair != NULL) && (impair != NULL)) {
for (int i = 1; i < argc; ++i) {
if (atoi(argv[i]) % 2 == 0) {
pair[taillepair] = atoi(argv[i]);
taillepair++;
} else {
impair[tailleimpair] = atoi(argv[i]);
tailleimpair++;
}
}
}
if (impair != NULL) {
for (int i = 1; i < argc; ++i) {
if (atoi(argv[i]) % 2 != 0) {
impair[tailleimpair] = atoi(argv[i]);
tailleimpair++;
}
}
}

for(int i = 0; i< taillepair; i++){
printf("%d ",pair[i]);
}
Expand Down
14 changes: 3 additions & 11 deletions TP7/ex2/TP7ex22.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,20 @@ int main (int argc, char** argv) {
for (int i = 1; i < argc; ++i) {
if (atoi(argv[i]) % 2 == 0) {
taillepairalloc++;
}
}
for (int i = 1; i < argc; ++i) {
if (atoi(argv[i]) % 2 != 0) {
} else {
tailleimpairalloc++;
}
}

pair = malloc ((taillepairalloc)*sizeof (int) ) ;
impair = malloc ((tailleimpairalloc)*sizeof (int) ) ;

if (pair != NULL) {
if ((pair != NULL) && (impair != NULL)) {
for (int i = 1; i < argc; ++i) {
if (atoi(argv[i]) % 2 == 0) {
pair[taillepair] = atoi(argv[i]);
taillepair++;
}
}
}
if (impair != NULL) {
for (int i = 1; i < argc; ++i) {
if (atoi(argv[i]) % 2 != 0) {
} else {
impair[tailleimpair] = atoi(argv[i]);
tailleimpair++;
}
Expand Down

0 comments on commit 2e12b06

Please sign in to comment.