Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please answer a and b for necessary use fortran program and thank you Sultan Qab

ID: 3826271 • Letter: P

Question

Please answer a and b for necessary use fortran program and thank you

Sultan Qaboos University College of Engineering Fortran Programming (ENGR2216) Spring 2017 Assignment 4 Date: April 16, 2017 Due Date: April 26, 2017 (a) Write a function that will receive a 1-D array of real numbers of size k. The function should return the average of that amay. (b) Write asubroutine that will receive a 2-Dof real numbers of size m by n, a 1-D amay of real numbers of size m, and a 1-D arrary ofreal numbers of size n. First: the subroutine will compute the average of the 2-D array Second: the subroutine wi cerate and return a 2-D array of size (m by (nt l) from the three arrays it received as follows: 1-D array 2-D array of size m by n of size m I-D array of size n Average of the 2-D arra

Explanation / Answer

Answered in C language

1)Function to return the Average of the Array of K elements
  
int computeAverage(int array[], int k){    // The function receives the Array array[] of size k
  
   int average;
   int i,j;
   int sum = 0;
   for(i = 0; i< k ; i++){
       sum+= array[i];
   }                                      // Compute the Sum of all the numbers in the Array.
   average = sum/k;                       // Average is the Sum divided by number of elements

   return average;                       //Return the Average of the elements in the Array of size k
}

2)This Function takes input a 2-D array of size (m,n) , 2 1-D arrays of size m and Size n and Return array of size(m+1, n+1)

int** returnAverageAndNewArray(int** array, int m, int n, int a[], int b[]){
  
   int i,j,average,sum = 0;
   int newArray[m+1][n+1];                 //Create a new Array of size(m+1,n+1)
  
   for(i = 0; i< m ;i++){
       for(j = 0; j< n; j++){
           sum += array[i][j];             // Sum stores the sum of all elements in the Array
       }
   }
   average = sum/(m+n);                   // Average is sum / total elements
  
   for(i = 0; i< m+1; i++){               // Create the New Array According to the given diagram
        for(j = 0; j< n+1 ; j++){
          
            if(i == m && j == n){          // Last cell (last row and last column)
                newArray[i][j] = average;
            }
            else if(i == m && j!= n){       //Last Row (m+1)th Row
                newArray[i][j] = b[j];
            }
            else if(i!= m && j == n){       //Last Column (n+1) Column
                newArray[i][j] = a[i];
            }
            else{
                newArray[i][j] = array[i][j]; //Else old array values
            }
        }
   }
  
   return newArray;                               //Return the final Array of size (m+1, n+1)
  
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote