Answer to Question #264813 in C++ for manci

Question #264813

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}. 


1
Expert's answer
2021-11-12T17:36:22-0500
#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;




}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS