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

Find all the errors in this C program 1/* Computes the sum of the array */ int s

ID: 3872613 • Letter: F

Question

Find all the errors in this C program

1/* Computes the sum of the array */ int sum(int n, int * arr) int i, sum; arr += n; sum += * (arr+i); 9 /* Fills the array with the values 10 * 1*2, 2-2, 3*2,..-, (n-1) 2, n*2 / 11 void fil!Squares(int n, int arr) 12 13 14 15 16 17 18 19 * Reads an integer n from arguments, 20 21 int i; arr [i] i*i; = Eree (arr) return arri * fills array with squares, and computes *the sum of the squares. Prints out the ksum before freeing all used memory. */ 23 int main(int argc, char argv]) 24 25 26 27 28 29 30 31 32 int n, totali int arr; if (ar printf ("usage: /squares n "); return l; n atoi (argv [2] ) ; arr= (int*) malloc (n); 34 35 36 37 38 39 40 fillSquares (arr) total = sum (arr) ; printf ("total: %d ", total); free (argv); 4 3

Explanation / Answer

1.In function sum you are not returning the value of sum to the function.

2.In function fillSquares return type should not bee void as it will not return anything.

3.In function fillSquares you dont have to do free(arr) here otherwise we wont be able to do further operation on array element.

4.In main method array declaration is wrong.

5.n=atoi(array[2])..error in this line.

6.Function fillSquare is getting called with incorrect parameters.

7.Function sum is getting called with incorrect parameters.

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