Question: Please help with this question (the two functions). I've attempted it but it's not working. We have to complete the 2 functions int largest(int *

Please help with this question (the two functions). I've attempted it but it's not working.

We have to complete the 2 functions int largest(int * x); and void display(int *arr); (one prints the values in array and the other gets max value in array).

But we can only use pointer indirection and address arithmetic to access and traverse the array. No array index [] should be used in the functions.

C PROGRAMMING:

-----------------

/* Passing an array to a function. */

#include #define MAX 20 int largest(int * x); void display(int *arr);

int main() { int array[MAX], count;

/* Input MAX values from the keyboard. */ int i; count=0; while ( scanf("%d", &i) != EOF){ *(array + count) = i; // store in array[count] count++; }

/* Call the function and display the return value. */ printf("Inputs: "); display(array);

printf(" Largest value: %d ", largest(array)); return 0; } /* display a int array */

void display(int *arr) { int s = 0; while(*arr != '\0') { s++; /* increase the address until the end */ } printf("%d", s); // int length = arr s; /* Subtract the two addresses, end - start */ // int i = 0; // for(i = 0; i < length; i++){ // printf("%d ", *(arr + i)); }

/* Function largest() returns the largest value */ /* in an integer array */

int largest(int *arr) { int *maximum = arr; int c = 0; for (c = 0; c < (sizeof(arr)*2)-1; c++){ if (*(arr+c) > *maximum) *maximum = *(arr+c); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!