Answer to Question #249895 in C++ for Hazzy

Question #249895

Exercise 3: Practice to manipulate data in arrays Write a C program to create an integer array called Motion of size 5. Ask the user to enter values to the array from the keyboard. Rotate the values of the array by one position in the forward direction and display the values.

Ex: number in index 4 should move to index 3, Number in index 3 should move to index2, number index 0 should move to index 4.

Initial values 10 6 8 2 9

After rotating 6 8 2 9 10


1
Expert's answer
2021-10-11T14:13:30-0400
#include<stdio.h>
#include<string.h>




int main() {


	int Motion[5];
	int i;
	int temp;
	for(i=0;i<5;++i){
		printf("Enter the value %d: ",(i+1));
		scanf("%d",&Motion[i]);
	}
	printf("Original array:\n");
	for( i=0;i<5;++i){
		printf("%d ",Motion[i]);
	}
	temp = Motion[0];
	for ( i = 0; i < 4; i++){
	    Motion[i] = Motion[i + 1];
	}
    
    Motion[4] = temp;


	printf("\n\nArray after right rotation:\n");
	for(i=0;i<5;++i){
		printf("%d ",Motion[i]);
	}




	scanf("%d",&Motion[0]);


	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