Created
July 1, 2012 22:45
-
-
Save josejuan/3029921 to your computer and use it in GitHub Desktop.
reduccion
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 mod4(int n) { | |
return n % 4; | |
} | |
int div4(int n) { | |
return n / 4; | |
} | |
int divX(int n, int x) { | |
return n / x; | |
} | |
int divX4(int n) { | |
return divX(n, 4); | |
} | |
int sumDiv5(int n) { | |
int d, s = 0; | |
for(d = 1; d <= 5; d++) | |
s += divX(n, d); | |
return s; | |
} | |
int distributiva(int N, int P) { | |
// 1 * P + 2 * P + ... + (N-1) * P + N * P = P * N * (N+1) / 2 | |
int i, S = 0; | |
for(i = 1; i <= N; i++) | |
S += i * P; | |
return S; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment