Tuesday, 30 September 2025

reverse an array c#

 // Online C# Editor for free

// Write, Edit and Run your C# code using C# Online Compiler


using System;


public class HelloWorld

{

    public static void Main(string[] args)

    {

        int[] ar={2,4,6,8,10,12,14};

         Console.WriteLine("Original Array:");

        Console.WriteLine(string.Join(", ", ar)); // comma-separated


        reverse(ar);


        Console.WriteLine("Reversed Array:");

        Console.WriteLine(string.Join(", ", ar)); // comma-separated

    }

    static void reverse(int[] ar){

        int i=0,j=ar.Length - 1;

        while(i < j){

            int t= ar[i];

            ar[i]=ar[j];

            ar[j]=t;

            i++;

            j--;

        }

    }

}

No comments:

Post a Comment

remove duplicates in an sorted array

  using System; public class HelloWorld {     public static void Main(string[] args)     {         int[] ar = { 2, 2, 3, 3, 4, 6, 6 };      ...