We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f106900 commit 585f286Copy full SHA for 585f286
solutions/c/multiples-of-3-and-5.c
@@ -0,0 +1,13 @@
1
+#include <stdio.h>
2
+
3
+int sum_of_multiples(int n)
4
+{ int sum=0;
5
+ n=n-1;
6
+ sum=((n/3)*((n/3)*3 +3))/2 + ((n/5)*((n/5)*5 +5))/2 - ((n/15)*((n/15)*15 + 15))/2; // sum of airthmetic progressions & De-Morgan's Law
7
+ return sum;
8
+}
9
+int main()
10
+{
11
+ printf("%d\n",sum_of_multiples(1000));
12
+ return 0;
13
0 commit comments