Problem 1

Statement
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.

Solution
The code, in C.

#include <stdio.h>

int sumMult(int a, int b){
  int t=0;
  int i;
  for(i=0;i<1000;i++){
    if(i%a==0 || i%b==0)
    t+=i;
  }
  return t;
}

int main(void){
  printf("%d\n",sumMult(3,5));
  return 0;
}

Answer
233168

No tags for this post.

SPEAK / ADD YOUR COMMENT
Comments are moderated.

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>