9511_workbook

solved exercises from algorithms & programming I (9511) prof. Cardozo
Index Commits Files Refs README
commit 706b793a291556587d1be8adff14d6bb3d6ce5a9
parent 95eb605b35e8c704289019031e50fab11c04dc20
Author: klewer-martin <martin.cachari@gmail.com>
Date:   Tue, 23 Mar 2021 18:28:27 -0300

Update: ex34.c;

Diffstat:
Mguia03/ex34.c | 20++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
diff --git a/guia03/ex34.c b/guia03/ex34.c
@@ -1,13 +1,25 @@
 #include <stdio.h>
+#include <stdbool.h>
 
-#define N_MAX 10
+#define N 10
+
+bool isSorted(int *vector, size_t size);
 
 int main (void) 
 {
-    int vector[N];
-
-            
+    int vector[N] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
 
+    printf("The vector is sorted: %s\n", isSorted(vector, N) ? "Yes" : "No");
 
     return 0;
 }
+
+bool isSorted(int *vector, size_t size)
+{
+    size_t i;
+    for(i = 1; (i < size) && (vector[i] >= vector[i - 1]); i++)
+        ;
+
+    return true * (size == i);
+}
+