glendaProblem 2621f54a18 years agoHistory
31 lines · 526 B · C
RawDownload
#include <u.h>#include <libc.h> /*If we list all the natural numbers below 10 that are multiplesof 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is23. Find the sum of all the multiples of 3 or 5 below 1000.*/ voidmain(){	int max = 1000;	int multiples[] = {3, 5};	int multipleslength = (&multiples)[1]-multiples;	int sum = 0; 	for(int i=0; i<max; i++){		for(int a=0; a<multipleslength; ++a) {			if(i % multiples[a] == 0){				sum += i;				break;			}		}	} 	print("Sum: %d\n", sum);	exits(0);}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t