Start tp5; add min-max
This commit is contained in:
parent
454b7e8dc5
commit
9b2bd53a75
2 changed files with 44 additions and 0 deletions
11
programmation-c-cpp/tp5/Makefile
Normal file
11
programmation-c-cpp/tp5/Makefile
Normal file
|
@ -0,0 +1,11 @@
|
|||
CFLAGS=-lm
|
||||
C_FILES=$(shell find . -name '*.*')
|
||||
TARGETS=$(notdir $(basename ${C_FILES}))
|
||||
|
||||
all: ${TARGETS}
|
||||
@for target in ${TARGETS}; do \
|
||||
grep -q $${target} ../../.gitignore || echo $${target} >> ../../.gitignore; \
|
||||
done
|
||||
|
||||
clean:
|
||||
rm -f ${TARGETS}
|
33
programmation-c-cpp/tp5/min-max.c
Normal file
33
programmation-c-cpp/tp5/min-max.c
Normal file
|
@ -0,0 +1,33 @@
|
|||
/* Minimum, maximum */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int min(int, int);
|
||||
int max(int, int);
|
||||
|
||||
int main() {
|
||||
int a, b;
|
||||
|
||||
a = 12;
|
||||
b = 9;
|
||||
|
||||
printf("Le min de %d et %d est %d\n", a, b, min(a, b));
|
||||
printf("Le max de %d et %d est %d\n", a, b, max(a, b));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int min(int a, int b) {
|
||||
if (a <= b) {
|
||||
return a;
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
int max(int a, int b) {
|
||||
if (a >= b) {
|
||||
return a;
|
||||
}
|
||||
return b;
|
||||
}
|
Loading…
Reference in a new issue