Created
June 30, 2016 16:06
-
-
Save souenzzo/9b262602c0b2abfdc84c562b1d1bba92 to your computer and use it in GitHub Desktop.
Resolução do desafio, sem usar variaveis.
This file contains 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> | |
// Pega o ultimo elemento | |
int tail(int num, int base) { | |
return num % base; | |
} | |
// Pega o corpo, menos o ultimo elemento | |
int init(int num, int base) { | |
return num / base; | |
} | |
// Insere no fim | |
int append(int num, int new, int base) { | |
return (num * base) + new; | |
} | |
int rev(int from, int to, int base) { | |
if (from == 0) | |
return to; | |
else | |
return rev(init(from, base), append(to, tail(from, base), base), base); | |
} | |
int desafio(int i) { | |
return rev(i, 0, 10); | |
} | |
int main (int argc, char **argv) { | |
if (argc != 2) { | |
return 1; | |
} | |
int n; | |
sscanf(argv[1], "%d", &n); | |
printf("%d\n", desafio(n)); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment