Skip to content
This repository was archived by the owner on Dec 12, 2023. It is now read-only.

Commit 8316198

Browse files
committed
Added solution to multiples-of-3-and-5 in C.
1 parent 4b98301 commit 8316198

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

solutions/c/multiples-of-3-and-5.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)