+ 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; }

28th Apr 2018, 11:08 AM
Mihail
Mihail - avatar
2 Antworten
+ 2
use this tmp=a[n]; for(i=n-1; i > 0; i--) a[i]=a[i-1]; a[0]=tmp;
28th Apr 2018, 12:31 PM
sajede mirzaei
sajede mirzaei - avatar
+ 1
thanks very much
28th Apr 2018, 6:24 PM
Mihail
Mihail - avatar