Maplewing

5/22 CSharp: evenSum

May 21st, 2016
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.70 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication7
  8. {
  9.     class Program
  10.     {
  11.         static int evenSum(int a, int b)
  12.         {
  13.             int sum = 0;
  14.             for (int i = a; i <= b; i++)
  15.             {
  16.                 if (i % 2 == 0)
  17.                 {
  18.                     sum += i;
  19.                 }
  20.             }
  21.  
  22.             return sum;
  23.         }
  24.  
  25.         static void Main(string[] args)
  26.         {
  27.             int a, b;
  28.             a = int.Parse( Console.ReadLine() );
  29.             b = int.Parse(Console.ReadLine());
  30.             Console.WriteLine(evenSum(a, b));
  31.         }
  32.     }
  33. }
Add Comment
Please, Sign In to add comment