TheBulgarianWolf

Odd Times

Jan 1st, 2021
1,105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.60 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace OddTimes
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             Console.WriteLine("Enter an array of numbers separated with space: ");
  11.             int[] numbers = Console.ReadLine().Split(" ").Select(int.Parse).ToArray();
  12.             int result = 0;
  13.             for (int i = 0; i < numbers.Length; i++)
  14.             {
  15.                 result = result ^ numbers[i];
  16.             }
  17.  
  18.             Console.WriteLine("The number which occurs odd number of times is: ");
  19.             Console.WriteLine(result);
  20.         }
  21.     }
  22. }
  23.  
Add Comment
Please, Sign In to add comment