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

index 4ec33b6317b8e0912d8b13bdb7d9930876964b86..7146249777a38a3071fedfe38420f7e0c1e75563 100644 (file)
@@ -1,11 +1,12 @@
 CC=gcc
 CFLAGS=-Wall -ansi -pedantic
 
-EXECS=ex1 ex2 ex3 ex4
+EXECS=ex1 ex2 ex3 ex4 ex5
 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
 
 all: ${EXECS}
 
@@ -21,5 +22,8 @@ ex3: ${EX3OBJ} aux.h
 ex4: ${EX4OBJ} aux.h
        gcc ${CFLAGS} -o $@ ${EX4OBJ}
 
+ex5: ${EX5OBJ} aux.h
+       gcc ${CFLAGS} -o $@ ${EX5OBJ}
+
 clean:
        rm -f *.o ${EXECS}
diff --git a/aula03/ex5.c b/aula03/ex5.c
new file mode 100644 (file)
index 0000000..f933230
--- /dev/null
@@ -0,0 +1,25 @@
+#include <stdio.h>
+#include <limits.h>
+#include "aux.h"
+
+#define NUMELEMS 100
+
+void quadradoVector(int v[], int tamanho);
+
+int main() {
+  int v[NUMELEMS], tam;
+
+  scanf("%d", &tam);
+  leVector(v, tam);
+  quadradoVector(v, tam);
+  escreveVector(v, tam);
+
+  return 0;
+}
+
+void quadradoVector(int v[], int tamanho) {
+  while (tamanho-- > 0)
+    v[tamanho] *= v[tamanho];
+}
+
+