Error in sorting array using vector

here is the code . it is reading the code and taking input put not giving desired output pls help me out

#include
#include
#include
using namespace std;
#include<stdio.h>

int main()
{
int n,i;
cin>>n;

vector A(n);

for(i=1;i<=n;++i)
{
scanf("%ld ",&A[i]);
}

sort(A.begin(),A.end());

for(i=0;i<n;++i)
{
printf("%ld ",A[i]);
}
return 0;
}

Kindly check the parameters of the loop, it should be from 0 to n-1

You are iterating from 1 to n

1 Like

thank you bro but sometimes i get error while using printf for displaying vector array
. is the format in the code right or can it be made more efficient??

WHY USING cin IF USING C LANGUAGE

i am using c++ the above header files are
#include< algorithm>
#include< vector >
#include< iostream >
using namespace std;