From: Alexandre P Francisco Date: Mon, 5 May 2014 23:03:32 +0000 (+0100) Subject: Updating aula07. X-Git-Url: http://web.ist.utl.pt/aplf/git/?a=commitdiff_plain;h=8a9d81e09153ce511f31208ad599189685bf5db6;p=iaed.git Updating aula07. --- diff --git a/aula07 b/aula07 deleted file mode 120000 index 053f3e1..0000000 --- a/aula07 +++ /dev/null @@ -1 +0,0 @@ -aula06 \ No newline at end of file diff --git a/aula07/Makefile b/aula07/Makefile new file mode 100644 index 0000000..d1b01cc --- /dev/null +++ b/aula07/Makefile @@ -0,0 +1,12 @@ +CC=gcc +CFLAGS=-Wall -ansi -pedantic + +EXECS=complexos + +all: ${EXECS} + +complexos: complexos.o + gcc ${CFLAGS} -o $@ $< + +clean: + rm -f *.o ${EXECS} diff --git a/aula07/complexos.c b/aula07/complexos.c new file mode 100644 index 0000000..e9cd959 --- /dev/null +++ b/aula07/complexos.c @@ -0,0 +1,77 @@ +/** + * Exercicios 4, 5 e 6 da aula 7. + */ + +#include +#include + +typedef struct { + float real, img; +} complexo; + +complexo le_complexo(); +void escreve_complexo(complexo a); + +complexo soma_ex4(complexo a, complexo b) { + a.real += b.real; + a.img += b.img; + + return a; +} + +void soma_ex5(complexo *pa, complexo b) { + pa->real += b.real; + pa->img += b.img; +} + +complexo * soma_ex6(complexo a, complexo b) { + complexo * psoma; + + psoma = malloc(sizeof(complexo)); + + psoma->real = a.real + b.real; + psoma->img = a.img + b.img; + + return psoma; +} + +int main() { + complexo x, y, z, *p; + + x = le_complexo(); + y = le_complexo(); + + z = soma_ex4(x, y); + escreve_complexo(z); + printf("\n"); + + soma_ex5(&x, y); + escreve_complexo(z); + printf("\n"); + + p = soma_ex6(x, y); + escreve_complexo(*p); + printf("\n"); + free(p); + + return EXIT_SUCCESS; +} + +complexo le_complexo() { + complexo a; + char sign; + + scanf("%f%c%fi", &a.real, &sign, &a.img); + + if (sign == '-') + a.img *= -1; + + return a; +} + +void escreve_complexo(complexo a) { + if (a.img >= 0) + printf("%f+%fi", a.real, a.img); + else + printf("%f%fi", a.real, a.img); +} diff --git a/aula07/ex7.c b/aula07/ex7.c new file mode 100644 index 0000000..581ab17 --- /dev/null +++ b/aula07/ex7.c @@ -0,0 +1,12 @@ + +int main() { + + int * p; + int ** pp; + int * v[20]; + int*(* f)(int, int); + void (*fv[10])(); + + return 0; +} +