stefan1919

Is an array Symmetric?

Aug 21st, 2015
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.90 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 ConsoleApplication4
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Console.WriteLine("Enter a positive integer: ");
  14.             int n = int.Parse(Console.ReadLine());
  15.             int[] array = new int[n];
  16.             Console.WriteLine("Enter the values of the array: ");
  17.             for (int i = 0; i < n; i++)
  18.             {
  19.                 array[i] = int.Parse(Console.ReadLine());
  20.             }
  21.             bool symmetric = true;
  22.             for (int j = 0; j < array.Length / 2; j++)
  23.             {
  24.                 if (array[j] != array[n - j - 1])
  25.                 {
  26.                     symmetric = false;
  27.                 }
  28.             }
  29.             Console.WriteLine("Is symmetric: {0}", symmetric);
  30.  
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment