Write a C+ program that that reads 10 values from an input file \"data.txt\" and
ID: 3820176 • Letter: W
Question
Write a C+ program that that reads 10 values from an input file "data.txt" and store them in an array. Your program asks the user to enter a positive number 'n' and then shifts 'n' times the contents of array cells one cell to the right, with the last cell's contents moved to the left end. Your program should use at least one function void shift (int A [], integral s, integral n) Run your program with the following input data 76, 89, 100, 90, 90, 100, 76, 100, 90, 87. Your output should be as following: Before 76 89 100 90 90 100 76 100 90 87 Enter a positive number 2 After: 90 87 76 89 100 90 90 100 76 100Explanation / Answer
void leftRotatebyOne(int A[], int n);
void leftRotate(int A[], int s, int n)
{
int i;
for (i = 0; i < s; i++)
leftRotatebyOne(A, n);
}
void leftRotatebyOne(int A[], int n)
{
int i, temp;
temp = A[0];
for (i = 0; i < n-1; i++)
A[i] =A[i+1];
A[i] = temp;
}
void printArray(int A[], int size)
{
int i;
for(i = 0; i < size; i++)
printf("%d ", A[i]);
}
int main()
{
int arr[] = {76, 89, 100, 90, 90, 100, 76, 100, 90, 87};
leftRotate(A, 2, 10);
printArray(A, 10);
getchar();
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.