]> web.ist.utl.pt Git - iaed.git/commitdiff
Adding ex2 for aula03.
authorAlexandre P Francisco <aplf@ist.utl.pt>
Wed, 12 Mar 2014 14:46:49 +0000 (14:46 +0000)
committerAlexandre P Francisco <aplf@ist.utl.pt>
Wed, 12 Mar 2014 14:46:49 +0000 (14:46 +0000)
aula03/ex2.c [new file with mode: 0644]

diff --git a/aula03/ex2.c b/aula03/ex2.c
new file mode 100644 (file)
index 0000000..8af2604
--- /dev/null
@@ -0,0 +1,32 @@
+#include <stdio.h>
+
+#define NUMELEMS 100
+
+void leVector(int a[], int tam);
+int somaVector(int a[], int tam);
+
+int main() {
+  int v[NUMELEMS], tam;
+
+  scanf("%d", &tam);
+  leVector(v, tam);
+  printf("%d\n", somaVector(v, tam));
+
+  return 0;
+}
+
+void leVector(int a[], int tam) {
+  int i;
+
+  for (i = 0; i < tam; i++)
+    scanf("%d", &a[i]);
+}
+
+int somaVector(int a[], int tam) {
+  int i, soma = 0;
+
+  for (i = 0; i < tam; i++)
+    soma += a[i];
+
+  return soma;
+}