Skip to content

Instantly share code, notes, and snippets.

@soravux
Last active December 15, 2015 23:08
Show Gist options
  • Select an option

  • Save soravux/5337644 to your computer and use it in GitHub Desktop.

Select an option

Save soravux/5337644 to your computer and use it in GitHub Desktop.
Solution to the Project Euler problem #1 - For the multigrad blog (entry 3)
#include <stdio.h>
unsigned int NumberIt()
{
/* Create a persistant variable x and initialize it to 0 */
static unsigned int x = 0;
for (x++; x < 1000; x++) {
if (x % 5 == 0 || x % 3 == 0) {
return x;
}
}
/* This section is for looping purposes */
x = 3;
return x;
}
int main()
{
unsigned int lResult, lTmpValue, lLoop;
for (lLoop = 0; lLoop <= 100000; lLoop++) {
lResult = 0;
while (1) {
lTmpValue = NumberIt();
if (lTmpValue > 1000) { break; }
lResult += lTmpValue;
}
}
printf("Result: %u\n", lResult);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment