Advertisement
grubcho

Array elements equal to their index

Jun 20th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.77 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 _2.Array_Elements_Equal_to_Their_Index
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string[] input = Console.ReadLine().Split(' ');
  14.             int[] numArray = new int[input.Length];
  15.             int index = 0;
  16.             string output = string.Empty;
  17.             for (int i = 0; i < numArray.Length; i++)
  18.             {
  19.                 numArray[i] = int.Parse(input[i]);
  20.                 if (numArray[i] == index)
  21.                 {
  22.                     output += input[i] + " ";
  23.                 }
  24.                 index++;
  25.             }
  26.             Console.WriteLine(output);
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement