+ 1
how to push all array element to the right?
//this program pushes all array numbers to the left. Can someone help me how to make it push them to the right? #include <iostream> using namespace std; int main() { int n,i; float tmp; cout<<"how many numbers should this array have?"<<endl; cin>>n; float a[n]; cout<<"enter the array numbers!"<<endl; for(i=0;i<n;i++) cin>>a[i]; tmp=a[0]; for(i=1;i<=n;i++) a[i-1]=a[i]; a[n-1]=tmp; cout<<"the new array is "; for(i=0;i<n;i++) cout<<a[i]; return 0; }
2 Answers
+ 2
use this
tmp=a[n];
for(i=n-1; i > 0; i--)
a[i]=a[i-1];
a[0]=tmp;
+ 1
thanks very much