Skip to content

Instantly share code, notes, and snippets.

@rogerioagjr
Created April 24, 2015 11:41
Show Gist options
  • Save rogerioagjr/2032c5619e46555643ee to your computer and use it in GitHub Desktop.
Save rogerioagjr/2032c5619e46555643ee to your computer and use it in GitHub Desktop.
mod
int mod(int x){ // declaro a função "mod" do tipo inteira que receberá um inteiro "x" como parâmetro
if(x>0) return x; // se x for maior que zero, ele é seu próprio módulo e retornamos ele mesmo
// se a função chegar nessa linha, então ela não retornou na linha anterior
return -x; // então x não é maior que zero e seu módulo será seu oposto, ou seja, -x.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment