Question

In: Computer Science

ASSIGNMENT: Write a program to reverse an array and then find the average of array elements....

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:

  • To reverse the order of the 2nd array, get the value of element [(10 - 1) - counter] of the 1st array and put it into element [counter] of the 2nd array
  • When displaying the arrays, the values are separated with tabs ('\t')

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

Solutions

Expert Solution

#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


Related Solutions

write a mips program to find the number of elements of the array that are divisible...
write a mips program to find the number of elements of the array that are divisible by 3.
Write a C program to show sum of 10 elements of array and show the average....
Write a C program to show sum of 10 elements of array and show the average. [10]
Write a C++ program to find K largest elements in a given array of integers. For...
Write a C++ program to find K largest elements in a given array of integers. For eeample, if K is 3, then your program should ouput the largest 3 numbers in teh array. Your program is not supposed to use any additional array.
Program in C: Write a program in C that reorders the elements in an array in...
Program in C: Write a program in C that reorders the elements in an array in ascending order from least to greatest. The array is {1,4,3,2,6,5,9,8,7,10}. You must use a swap function and a main function in the code. (Hint: Use void swap and swap)
Write an ARMv8 program to sort an array of elements. As Imentioned in class, this...
Write an ARMv8 program to sort an array of elements. As I mentioned in class, this problem uses a portion of your Programming Assignment 1 where you computed the smallest and largest values in an array. Here we will extend that assignment to find the “index” of the smallest and the index of the largest elements of the array. The following C code segment illustrates how we can sort the element of an array.For this problem, assume an array with...
Write a program in MIPS to find the largest element of an array, the array size...
Write a program in MIPS to find the largest element of an array, the array size should be less than or equal to 10. Has to be extremely basic, cannot use stuff like move. Very basic. Here is what I already have and I am stuck. .data myarray: .word 0,0,0,0,0,0,0,0,0,0 invalid: .asciiz "Number is invalid, store a number in the array that is from 0-10.\n" large: .asciiz "The largest element is " colon: .asciiz " :\t" enter: .asciiz "Store a...
REVERSE POLISH CALCULATOR C++ ONLY. For this assignment, you are to write a program, which will...
REVERSE POLISH CALCULATOR C++ ONLY. For this assignment, you are to write a program, which will calculate the results of Reverse Polish expressions that are provided by the user. You must use a linked list to maintain the stack for this program (NO array implementations of the stack). You must handle the following situations (errors): Too many operators (+ - / *) Too many operands (doubles) Division by zero The program will take in a Polish expression that separates the...
Write C program that reorders elements of an array of integers such that the new order...
Write C program that reorders elements of an array of integers such that the new order is in descending order (first number being the largest). Must have a main function and a swap function. - int main() will declare an array with the values { 32, 110, 79, 18, 22, 2}. This array will be passed to the swap function. - the void swap function will perform the necessary operations to reorder the elements of the array. - After swap()...
2. Write a program in C++ that: a) Declares a 1D array A with 30 elements...
2. Write a program in C++ that: a) Declares a 1D array A with 30 elements b) Inputs an integer n from 1-30 from the keyboard. If n < 1 set n = 1. If n > 30 set n = 30. the program should keep asking the user the input n one by one, followed by printing of the value of n (n=n if bigger than 1 and smaller than 30, 1 if smaller than 1 and 30 if...
Write a c program Write a function to swap two elements of an integer array. Call...
Write a c program Write a function to swap two elements of an integer array. Call the function to swap the first element, i[0] with last element i[n], second element i[1] with the last but one element i[n-1] and so on. Should handle arrays with even and odd number of elements. Call the swap function with the following arrays and print results in each case before and after swapping. i. int arr1[] = {0, 1, 2, 3, 30, 20, 10,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT