Reverse an array

    0

    0

    Aakanksha Priya

    Reverse an array using iterative approach.

    def reverse(arr,start,end):
        while(start<end):
            arr[start],arr[end] = arr[end],arr[start]
            start+=1
            end-=1
    #get array elements from user
    arr=[]
    n = int(input("Enter length of array:"))
    for i in range(0,n,1):
        arr.append(int(input()))
    reverse(arr,0,n-1)
    #print array elements with space
    print(*arr)
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    Legal
    • Security
    • Privacy Policy
    • Code Privacy
    • Terms of Service
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.