]> web.ist.utl.pt Git - iaed.git/commitdiff
Adding ex6 in aula03.
authorAlexandre P Francisco <aplf@ist.utl.pt>
Thu, 13 Mar 2014 16:14:35 +0000 (16:14 +0000)
committerAlexandre P Francisco <aplf@ist.utl.pt>
Thu, 13 Mar 2014 16:14:35 +0000 (16:14 +0000)
aula03/Makefile
aula03/ex6.c [new file with mode: 0644]

index 7146249777a38a3071fedfe38420f7e0c1e75563..af3a0447bdb3f5b70e722583a278122daae8f127 100644 (file)
@@ -1,12 +1,13 @@
 CC=gcc
 CFLAGS=-Wall -ansi -pedantic
 
-EXECS=ex1 ex2 ex3 ex4 ex5
+EXECS=ex1 ex2 ex3 ex4 ex5 ex6
 EX1OBJ=ex1.o aux.o
 EX2OBJ=ex2.o aux.o
 EX3OBJ=ex3.o aux.o
 EX4OBJ=ex4.o aux.o
 EX5OBJ=ex5.o aux.o
+EX6OBJ=ex6.o aux.o
 
 all: ${EXECS}
 
@@ -25,5 +26,8 @@ ex4: ${EX4OBJ} aux.h
 ex5: ${EX5OBJ} aux.h
        gcc ${CFLAGS} -o $@ ${EX5OBJ}
 
+ex6: ${EX6OBJ} aux.h
+       gcc ${CFLAGS} -o $@ ${EX6OBJ}
+
 clean:
        rm -f *.o ${EXECS}
diff --git a/aula03/ex6.c b/aula03/ex6.c
new file mode 100644 (file)
index 0000000..cc65d75
--- /dev/null
@@ -0,0 +1,29 @@
+#include <stdio.h>
+#include <limits.h>
+#include "aux.h"
+
+#define NUMELEMS 100
+
+void inverteVector(int v[], int tamanho);
+
+int main() {
+  int v[NUMELEMS], tam;
+
+  scanf("%d", &tam);
+  leVector(v, tam);
+  inverteVector(v, tam);
+  escreveVector(v, tam);
+
+  return 0;
+}
+
+void inverteVector(int v[], int tamanho) {
+  int i, t;
+  for (i = 0; i < (tamanho - 1)/2; i++) {
+    t = v[i];
+    v[i] = v[tamanho-i-1];
+    v[tamanho-i-1] = t;
+  }
+}
+
+