From: Alexandre P Francisco Date: Thu, 13 Mar 2014 16:05:03 +0000 (+0000) Subject: Adding ex4 in aula03. X-Git-Url: http://web.ist.utl.pt/aplf/git/?a=commitdiff_plain;h=86380259f5b5f984464758fa1f02457809e7142f;p=iaed.git Adding ex4 in aula03. --- diff --git a/aula03/Makefile b/aula03/Makefile index 92b3f5c..4ec33b6 100644 --- a/aula03/Makefile +++ b/aula03/Makefile @@ -1,11 +1,11 @@ CC=gcc CFLAGS=-Wall -ansi -pedantic -EXECS=ex1 ex2 ex3 +EXECS=ex1 ex2 ex3 ex4 EX1OBJ=ex1.o aux.o EX2OBJ=ex2.o aux.o EX3OBJ=ex3.o aux.o - +EX4OBJ=ex4.o aux.o all: ${EXECS} @@ -18,5 +18,8 @@ ex2: ${EX2OBJ} aux.h ex3: ${EX3OBJ} aux.h gcc ${CFLAGS} -o $@ ${EX3OBJ} +ex4: ${EX4OBJ} aux.h + gcc ${CFLAGS} -o $@ ${EX4OBJ} + clean: rm -f *.o ${EXECS} diff --git a/aula03/ex4.c b/aula03/ex4.c new file mode 100644 index 0000000..d55971f --- /dev/null +++ b/aula03/ex4.c @@ -0,0 +1,27 @@ +#include +#include +#include "aux.h" + +#define NUMELEMS 100 + +int procura(int v[], int tamanho, int k); + +int main() { + int v[NUMELEMS], tam, k; + + scanf("%d", &tam); + leVector(v, tam); + scanf("%d", &k); + printf("%d found at pos: %d\n", k, procura(v, tam, k)); + + return 0; +} + +int procura(int v[], int tamanho, int k) { + while (tamanho-- > 0) + if (v[tamanho] == k) + return tamanho; + + return -1; +} +