Last active
August 29, 2015 14:17
-
-
Save tkovs/52a618de470fd55eecbd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#define SIZE 10 | |
#define MAX(a,b) a > b ? a : b | |
int foo(int *x, int *y); | |
int bar(int *x, int size); | |
int main(void) | |
{ | |
int x[SIZE] = {5, 7, 3, 1, 8, 5, 3, 2, 4, 5}; | |
printf("foo: %d\n", foo(x, x + SIZE-1)); | |
printf("bar: %d\n", bar(x, SIZE)); | |
return 0; | |
} | |
int foo(int *x, int *y) | |
{ | |
if (x == y) { return *x; } | |
return MAX(*x, foo(x + 1, y)); | |
} | |
int bar(int *x, int size) | |
{ | |
int i = 0; | |
int maior = x[0]; | |
if (size == 1) { return *x; } | |
for (i = 1; i < size; i++) { | |
if (x[i] > maior) { | |
maior = x[i]; | |
} | |
} | |
return maior; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment