Last active
December 15, 2015 23:08
-
-
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)
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 characters
| #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