In: Computer Science
ASSIGNMENT:
Write a program to reverse an array and then find the average of array elements.
Start by creating 2 arrays that can each hold 10 integer values. Then, get values from the user and populate the 1st array. Next, populate the 2nd array with the values from the 1st array in reverse order. Then, average the corresponding elements in the 1st and 2nd arrays to populate a 3rd array (average the 1st element of the 1st array with the 1st element of the 2nd array and store the average in the 1st element of the 3rd array, average the 2nd element of the 1st array with the 2nd element of the 2nd array and store the average in the 2nd element of the 3rd array, and so forth). Finally, display all 3 arrays. Use loops to cycle through the arrays when both populating and displaying the arrays.
There is no validation.
Hints:
Example Run:
(bold type is what is entered by the user)
Enter array element #1: 5
Enter array element #2: 4
Enter array element #3: 7
Enter array element #4: 8
Enter array element #5: 2
Enter array element #6: 1
Enter array element #7: 3
Enter array element #8: 6
Enter array element #9: 9
Enter array element #10: 0
The original array...
5 4 7 8 2 1 3 6 9 0
The reverse array...
0 9 6 3 1 2 8 7 4 5
The average array...
x.x x.x x.x x.x x.x x.x x.x x.x x.x x.x
The example run shows EXACTLY how your program input and output will look.
C prog no Floats
#include<stdio.h>
int main(){
int arr1[10],arr2[10],arr3[10];
for(int i=0;i<10;i++){
printf("Enter array element #%d:
",i+1);
scanf("%d",&arr1[i]);
}
for(int i=0,j=9;i<10;i++,j--)
arr2[i]=arr1[j];
for(int i=0;i<10;i++)
arr3[i]=(arr1[i]+arr2[i])/2;
printf("The original array...\n");
for(int i=0;i<10;i++)
printf("%d ",arr1[i]);
printf("\nThe reverse array...\n");
for(int i=0;i<10;i++)
printf("%d ",arr2[i]);
printf("\nThe average array...\n");
for(int i=0;i<10;i++)
printf("%d ",arr3[i]);
}
NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.
I AM HERE TO HELP YOUIF YOU LIKE MY ANSWER PLEASE RATE AND HELP ME IT IS VERY IMP FOR ME