Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- public class problem
- {
- static void Main()
- {
- Problem();
- Solution();
- }
- static void Problem()
- {
- Console.WriteLine("\nAdd all the natural numbers below one thousand that are multiples of 3 or 5.");
- }
- static void Solution()
- {
- int a;
- int b;
- int sum = 0;
- int cap = 1000;
- for (int i = 0; i < cap; i++)
- {
- a = i % 3;
- b = i % 5;
- if ((a == 0) || (b == 0))
- sum += i;
- }
- Console.WriteLine("\n{0}\n", sum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment