Write a loop that sets newScores to oldScores shifted once left, with element 0 copied to the end. Ex: If oldScores = {10, 20, 30, 40}, then newScores = {20, 30, 40, 10}.
#include <iostream>
using namespace std;
int main() {
const int size = 4;
int oldScores[size];
int newScores[size];
int i;
for (i = 0; i < size; ++i) {
cin >> oldScores[i];
}
int last=oldScores[0];
for (int i=0;i<(size-1);i++)
newScores[i] = oldScores[i + 1];
newScores[size-1] = last;
for (i = 0; i < size; ++i) {
cout << newScores[i] << " ";
}
cout << endl;
return 0;
}
Comments
Leave a comment