Advertisement
aspire12

6.EvenAndOddSubstraction

Feb 8th, 2020
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.78 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _6.EvenAndOddSubstraction
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             //Write a program that calculates the difference between the sum of the even and the sum of the odd numbers in an array.
  10.  
  11.             string[] input = Console.ReadLine().Split();
  12.             double sumEven = 0, sumOdd = 0;
  13.             for (int i = 0; i < input.Length; i++)
  14.             {
  15.                 double number = double.Parse(input[i]);
  16.                 if(number % 2 == 0)
  17.                 {
  18.                     sumEven += number;
  19.                 }
  20.                 else
  21.                 {
  22.                     sumOdd += number;
  23.                 }
  24.             }
  25.             Console.WriteLine(sumEven - sumOdd);
  26.  
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement