Created
April 24, 2015 11:41
-
-
Save rogerioagjr/2032c5619e46555643ee to your computer and use it in GitHub Desktop.
mod
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
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