bhalash

Project Euler problem #1 solution.

May 29th, 2012
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.50 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. public class problem
  5. {
  6.     static void Main()
  7.     {
  8.         Problem();
  9.         Solution();
  10.     }
  11.  
  12.     static void Problem()
  13.     {
  14.         Console.WriteLine("\nAdd all the natural numbers below one thousand that are multiples of 3 or 5.");
  15.     }
  16.  
  17.     static void Solution()
  18.     {
  19.         int a;
  20.         int b;
  21.  
  22.         int sum = 0;
  23.         int cap = 1000;
  24.  
  25.         for (int i = 0; i < cap; i++)
  26.         {
  27.             a = i % 3;
  28.             b = i % 5;
  29.  
  30.             if ((a == 0) || (b == 0))
  31.                 sum += i;
  32.         }
  33.  
  34.         Console.WriteLine("\n{0}\n", sum);
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment