Skip to content

Instantly share code, notes, and snippets.

@CraigRodrigues CraigRodrigues/problem1.c Secret
Created Jun 29, 2016

Embed
What would you like to do?
Project Euler - Problem 1
#include <cs50.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/* If we list all the natural numbers below 10 that are multiples of 3 or 5,
* we get 3, 5, 6 and 9. The sum of these multiples is 23.
*
* Find the sum of all the multiples of 3 or 5 below 1000.
*/
int main(void)
{
int sum = 0;
for (int i=1; i < 1000; i++)
{
if (i % 3 == 0 || i % 5 == 0)
sum += i; //how do I write this shorter again?
}
printf("Final sum = %i\n", sum);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.