Arrays Introduction

  • + 0 comments

    If segmentation error keeps coming up in the test case

    #include <cmath>
    #include <cstdio>
    #include <vector>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    
    
    int main() {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT */   
        int n;
        cin>>n;
        int *arr = new int[n];
        
        for(int i=0 ; i<n ; i++)
        {
            cin>>arr[i];
        }
        int start = 0;
        int end = n-1;
        while(start<=end)
        {
            int temp = arr[start]; //swapping 
            arr[start] = arr[end];
            arr[end] = temp;
            start++;
            end--;
        }
        for(int i=0;  i<n ; i++)
        {
            cout<<arr[i]<<" ";
        }
        return 0;
    }