Friday, 6 June 2014

Project Euler Problem-1 Solution

/*
    Prob#1:    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.
*/


Code:

#include<stdio.h>
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
int main (){

  long int i=1,sum=0,testsum=0,value1=3,value2=5;
 
   for(;i < 1000;){
    
     testsum = value1*i;
     if(testsum < 1000){
      sum+=testsum;
     }
     testsum=value2*i;
     if(testsum < 1000){
      if(testsum % value1 != 0){
       sum += testsum;
      }
     }
     i++;
       }
   printf("The result is = %ld\n",sum);
 
 return 0;
}