lololol

C++ code posted
created at 21 Jan 02:44, updated at 21 Jan 20:50

Edit | Back
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <iostream>
#include <ctime>
using namespace std;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Problem: #1 Find the sum of all the multiples of 3 or 5 below 1000.
//
//  Example: 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.
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main()
{
  clock_t tStart = clock(); //This line is to start the clock calculating execution time

  int sum=0, i=1, j=1;
  while(i*3<1000)
  {
    if((i*3)%5 == 0)
      i++;
    else
    {
      sum += (i*3);
      i++;
    }
  }

  while(j*5 <1000)
  {
    sum += (j*5);
    j++;
  }
  cout << sum << endl;

  printf("Execution Time: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC); //Stop clock and print execution time
  return 0;
}
979 Bytes in 4 ms with coderay