]> web.ist.utl.pt Git - iaed.git/commitdiff
Updating aula07.
authorAlexandre P Francisco <aplf@ist.utl.pt>
Mon, 5 May 2014 23:03:32 +0000 (00:03 +0100)
committerAlexandre P Francisco <aplf@ist.utl.pt>
Mon, 5 May 2014 23:03:32 +0000 (00:03 +0100)
aula07 [deleted symlink]
aula07/Makefile [new file with mode: 0644]
aula07/complexos.c [new file with mode: 0644]
aula07/ex7.c [new file with mode: 0644]

diff --git a/aula07 b/aula07
deleted file mode 120000 (symlink)
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 (file)
index 0000000..d1b01cc
--- /dev/null
@@ -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 (file)
index 0000000..e9cd959
--- /dev/null
@@ -0,0 +1,77 @@
+/**
+ * Exercicios 4, 5 e 6 da aula 7.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+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 (file)
index 0000000..581ab17
--- /dev/null
@@ -0,0 +1,12 @@
+
+int main() {
+
+  int * p;
+  int ** pp;
+  int * v[20];
+  int*(* f)(int, int);
+  void (*fv[10])();
+
+  return 0;
+}
+