aboutsummaryrefslogtreecommitdiff
path: root/semestre 2/informatique/tme/semaine1/06_signe_produit.c
diff options
context:
space:
mode:
Diffstat (limited to 'semestre 2/informatique/tme/semaine1/06_signe_produit.c')
-rw-r--r--semestre 2/informatique/tme/semaine1/06_signe_produit.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/semestre 2/informatique/tme/semaine1/06_signe_produit.c b/semestre 2/informatique/tme/semaine1/06_signe_produit.c
new file mode 100644
index 0000000..764f184
--- /dev/null
+++ b/semestre 2/informatique/tme/semaine1/06_signe_produit.c
@@ -0,0 +1,20 @@
+#include <assert.h>
+
+int signeProduit(int a, int b){
+ if (a == 0 || b == 0) return 0;
+ else if (
+ (a < 0 && b > 0) || (a > 0 && b < 0)
+ ) return -1;
+ return 1;
+}
+
+int main(){
+ assert(signeProduit(0, 0) == 0);
+ assert(signeProduit(1, 0) == 0);
+ assert(signeProduit(0, -1) == 0);
+ assert(signeProduit(1, 1) == 1);
+ assert(signeProduit(-1, -1) == 1);
+ assert(signeProduit(1, -1) == -1);
+ assert(signeProduit(-1, 1) == -1);
+ return 0;
+}