]> web.ist.utl.pt Git - iaed.git/commitdiff
Adding ex6
authorAlexandre P Francisco <aplf@ist.utl.pt>
Tue, 11 Mar 2014 19:02:17 +0000 (19:02 +0000)
committerAlexandre P Francisco <aplf@ist.utl.pt>
Tue, 11 Mar 2014 19:02:17 +0000 (19:02 +0000)
aula02/ex6.c [new file with mode: 0644]

diff --git a/aula02/ex6.c b/aula02/ex6.c
new file mode 100644 (file)
index 0000000..17ac4ae
--- /dev/null
@@ -0,0 +1,20 @@
+#include <stdio.h>
+
+int main() {
+  int n, dc = 0, ds = 0;
+
+  do {
+    printf("NĂºmero positivo: ");
+    scanf("%d", &n);
+  } while (n <= 0);
+
+  while (n != 0) {
+    ds += n%10;
+    n /= 10;
+    dc ++;
+  }
+
+  printf("#dig: %d, sum: %d\n", dc, ds);
+
+  return 0;
+}