]> web.ist.utl.pt Git - iaed.git/commitdiff
Adding ex2
authorAlexandre P Francisco <aplf@ist.utl.pt>
Mon, 10 Mar 2014 23:11:50 +0000 (23:11 +0000)
committerAlexandre P Francisco <aplf@ist.utl.pt>
Mon, 10 Mar 2014 23:11:50 +0000 (23:11 +0000)
aula02/ex2.c [new file with mode: 0644]

diff --git a/aula02/ex2.c b/aula02/ex2.c
new file mode 100644 (file)
index 0000000..ef598b5
--- /dev/null
@@ -0,0 +1,28 @@
+#include <stdio.h>
+#include <values.h>
+
+float menor(float a, float b) {
+  return (a < b) ? a : b;
+}
+
+float maior(float a, float b) {
+  return (a > b) ? a : b;
+}
+
+int main() {
+  int n;
+  float min = FLT_MAX, max = -FLT_MAX, x;
+
+  scanf("%d", &n);
+
+  while (n--) {
+    scanf("%f", &x);
+    min = menor(min, x);
+    max = maior(max, x);
+  }
+
+  printf("min: %f, max: %f\n", min, max);
+
+  return 0;
+}
+