Skip to content

Instantly share code, notes, and snippets.

@souenzzo souenzzo/rev.c
Created Jun 30, 2016

What would you like to do?
Resolução do desafio, sem usar variaveis.
#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;
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
You can’t perform that action at this time.