Last active
December 15, 2015 13:59
-
-
Save diegotoral/5271335 to your computer and use it in GitHub Desktop.
Revisions
-
diegotoral revised this gist
Mar 29, 2013 . 1 changed file with 27 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,21 +1,41 @@ #include <stdio.h> int s (int x) { if (x == 0) return 0; else if (x == 1) return 1; else return x * x; } int main (int argc, char *argv[]) { int i, n, soma = 0; scanf("%d", &n); if (n % 2 == 0) { for (i = 1; i <= n / 2; i += 1) { soma += i + (i * i); } } else { for (i = 1; i <= (n - 1) / 2; i += 1) { soma += i + (i * i); } soma += (n + 1) / 2; } printf("\nSoma: %d\n", soma); return 0; } -
diegotoral revised this gist
Mar 29, 2013 . 1 changed file with 7 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -3,16 +3,19 @@ int main (int argc, char *argv[]) { int i, n, soma = 1; scanf("%d", &n); for (i = 1; i < n; i += 1) { if (i % 2) soma += i*i; else soma += i; } printf("Soma: %d\n", soma); return 0; } -
diegotoral created this gist
Mar 29, 2013 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ #include <stdio.h> int main (int argc, char *argv[]) { int i, n, soma = 0; scanf("%d", &n); for (i = 0; i < n; i += 1) { soma += (i + (i*i)); } printf("Soma: %d", soma); return 0; }