CSCI 201 CS Fisher Fall 2017 Closed Lab#7 10-24-17 Objective: To give students e
ID: 3599958 • Letter: C
Question
CSCI 201 CS Fisher Fall 2017 Closed Lab#7 10-24-17 Objective: To give students experience manipulating and passing arrays. Write a program that contains code for each of the following items. Write the code in the program and document it according to the numbered item below such as: I part a a. Declare a constant called A SIZE which equals the value 10. Declare an array called scores which contains ten elements of type int and use the constant A SIZE. Declare the variables x and y and set their values to 5 and 10. Initialize the values of the elements of the array to five times the index values. b. Write a displayScores0 which is passed the array scores and A SIZE. Print out the values of the array by using a for-loop. c. Set every other value in the scores array to x. Call displayScoreso. d. Increment the value of the first, fifth, and last elements of the array by y and set those values to the second, third, and fourth elements in the array. Call displayScoresO Set the value of the 2nd array element to the 3rd array element; set the value of the e. 4th array element to the 5th array element; set the value of the 6h array element to the 7th array element, and set the value of the 8th array element to the 9th array element. Call displayScores0 f. Write displayScoresReverse0 which displays the values of the array in reverse order. displayScoresReverse0 is passed the array and A SIZE. Call displayScoresReverseO from main0. g. Prompt the user for values for the first, second and last elements of the array. Call displayScores0. h. Display only the values of the array with indexes that are even. (You can write this code in main0). i. Change the value of each element in the array by setting the elements by the formula: (i *3)-2 given that i is the value of the array index. Call displayScores0Explanation / Answer
I will provide you with the C code of the questions.Do give it a thumbs up.
#include <stdio.h>
void displayScores(int arr[],int size)
{
int i;
for(i=0;i<size;i++)
printf("%d ",arr[i]);
printf(" ");
}
void displayScoresReverse(int arr[],int size)
{
int i;
for(i=size-1;i>=0;i--)
printf("%d ",arr[i]);
printf(" ");
}
void addValues(int arr[],int size)
{
int sum=0;
int i;
for(i=0;i<size;i++)
sum+=arr[i];
printf("%d ",sum);
}
void changeValues(int arr[],int size)
{
int i;
for(i=0;i<size-1;i++)
arr[i]=arr[i]+arr[i+1];
}
int main()
{
//part a
const int A_SIZE=10;
int scores[A_SIZE];
int i,x=5,y=10;
for(i=0;i<A_SIZE;i++)
scores[i]=i*5;
//part c
for(i=0;i<A_SIZE;i+=2)
scores[i]=x;
displayScores(scores,A_SIZE);
//part d
scores[1]=scores[0]+y;
scores[2]=scores[4]+y;
scores[3]=scores[9]+y;
displayScores(scores,A_SIZE);
//part e
scores[1]=scores[2];
scores[3]=scores[4];
scores[5]=scores[6];
scores[7]=scores[8];
displayScores(scores,A_SIZE);
//part f
displayScoresReverse(scores,A_SIZE);
//part g
printf("Enter first element");
scanf("%d",&scores[0]);
printf("Enter second element");
scanf("%d",&scores[1]);
printf("Enter last element");
scanf("%d",&scores[9]);
displayScores(scores,A_SIZE);
//part h
for(i=0;i<A_SIZE;i++)
if(i%2==0)
printf("%d ",scores[i]);
printf(" ");
//part i
for(i=0;i<A_SIZE;i++)
scores[i]=i*3-2;
displayScores(scores,A_SIZE);
//part j
addValues(scores,A_SIZE);
//part k
changeValues(scores,A_SIZE);
displayScores(scores,A_SIZE);
return 0;
}