From: Alexandre P Francisco Date: Thu, 13 Mar 2014 16:14:35 +0000 (+0000) Subject: Adding ex6 in aula03. X-Git-Url: http://web.ist.utl.pt/aplf/git/?a=commitdiff_plain;h=d6d86b29cae0ef18586149a5a4d10d837b11c497;p=iaed.git Adding ex6 in aula03. --- diff --git a/aula03/Makefile b/aula03/Makefile index 7146249..af3a044 100644 --- a/aula03/Makefile +++ b/aula03/Makefile @@ -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 index 0000000..cc65d75 --- /dev/null +++ b/aula03/ex6.c @@ -0,0 +1,29 @@ +#include +#include +#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; + } +} + +