Skip to content

Instantly share code, notes, and snippets.

@jonsterling
Created August 18, 2010 06:16
Show Gist options
  • Select an option

  • Save jonsterling/533666 to your computer and use it in GitHub Desktop.

Select an option

Save jonsterling/533666 to your computer and use it in GitHub Desktop.
#include <stdio.h>
int main () {
size_t n = 100;
int odds[n];
size_t i;
for(i = 0; i < n; ++i) {
odds[i] = 2 * i + 1;
}
size_t j;
for(j = 0; j < n; ++j) {
printf("%s%i%s", (j != 0 ? "," : "["), odds[j], (j == (n-1) ? "]" : ""));
}
return 0;
}
main = print [2*i + 1 | i <- [0..99]]
#include <stdio.h>
int main () {
size_t n = 100;
int odds[n];
size_t i;
for(i = 0; i < n; ++i) {
odds[i] = 2 * i + 1;
}
size_t j;
int s = 0;
for(j = 0; j < n; ++j) {
s = s + odds[j];
printf("%s%i%s", (j != 0 ? "," : "["), odds[j], (j == (n-1) ? "]" : ""));
}
printf("\nsum: %i", s);
return 0;
}
main = print odds >> print ("sum: " ++ (show . sum) odds)
where odds = [2*i + 1 | i <- [0..99]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment