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 <stdio.h>
#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("\nLargest value: %d\n", 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\n", *(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);
}
}
Code in C:
#include <stdio.h>
#define MAX 20
int largest(int * x);
void display(int *arr);
int main()
{
int array[MAX], count;
int i;
//take MAX number of inputs from user
for(i=0;i<MAX;i++)
{
scanf("%d",(array+i));
}
//display() function calling
printf("Elements in the array are: ");
display(array);
//display largest() function calling and print the
value
printf("\nLargest value: %d\n", largest(array));
return 0;
}
void display(int *arr)
{
int i;
//*(arr+i) gives the value of arr at ith index
for(i=0;i<MAX;i++)
printf("%d ",*(arr+i));
}
int largest(int *arr)
{
int max_value=*arr,i;
//Iterate entire array
for(i=1;i<MAX;i++)
{
//If value at ith index is greate
than max_value then update the max_value
if(*(arr+i)>max_value)
max_value=*(arr+i);
}
return max_value;
}
output screenshot:

Please help with this question (the two functions). I've attempted it but it's not working. We...
2. Pointer arithmetic: a) Write a printString function that prints a string (char-by-char) using pointer arithmetics and dereferencing. b) Write a function “void computeMinMax(double arr[], int length, double * min, double * max)” that finds the minimum and the maximum values in an array and stores the result in min and max. You are only allowed to use a single for loop in the function (no while loops). Find both the min and the max using the same for loop....
I need some with this program, please look at the changes I need closely. Its running correctly, but I need to do a few adjustments here is the list of changes I need: 1. All of the integers on a single line, sorted in ascending order. 2. The median value of the sorted array on a single line 3. The average of the sorted array on a single line Here is the program: #include<stdio.h> #include<stdlib.h> /* This places the Adds...
I JUST NEED HELP WITH DISPLAY PART!
please help!
thanks in advance
// This function saves the array of structures to file. It is already implemented for you.
// You should understand how this code works so that you know how to use it for future assignments.
void save(char* fileName)
{
FILE* file;
int i;
file = fopen(fileName, "wb");
fwrite(&count, sizeof(count), 1, file);
for (i = 0; i < count; i++)
{
fwrite(list[i].name, sizeof(list[i].name), 1, file);
fwrite(list[i].class_standing, sizeof(list[i].class_standing), 1, file);...
Please help in C: with the following code, i am getting a random 127 printed in front of my reverse display of the array. The file i am pulling (data.txt) is: 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 when the reverse prints, it prints: 127 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 not sure why...please...
Pointer arithmetic: a) Write a printString function that prints a string (char-by-char) using pointer arithmetics and dereferencing. b) Write a function “void computeMinMax(double arr[], int length, double * min, double * max)” that finds the minimum and the maximum values in an array and stores the result in min and max. You are only allowed to use a single for loop in the function (no while loops). Find both the min and the max using the same for loop. Remember...
C Programming write two functions, similar to what you see in the sample program. The first will ask the user to enter some information (I have included the type in parentheses) First Name (char[]) Last Name (char[]) Age (int) Height in Inches (double) Weight in Pounds (double) You will use pass-by-reference to modify the values of the arguments passed in from the main(). Remember that arrays require no special notation, as they are passed by reference automatically, but the other...
How can I convert the following C code to MIPS Assembly? +++++++++++++++++++++++++++++++++ MIPS main program ++++++++++++++++++++++++++++++++ .data # Defines variable section of an assembly routine. array: .word x, x, x, x, x, x, x, x, x, x # Define a variable named array as a word (integer) array # with 10 unsorted integer numbers of your own. # After your program has run, the integers in this array # should be sorted. .text # Defines the start of the code...
Writing a program in C please help!! My file worked fine before but when I put the functions in their own files and made a header file the diplayadj() funtion no longer works properly. It will only print the vertices instead of both the vertices and the adjacent like below. example input form commnd line file: A B B C E X C D A C The directed edges in this example are: A can go to both B and...
If void * is a pointer to void is a "generic" pointer type, and a void * can be converted to any other pointer type * without an explicit cast, why in the ,myarrcopy function the malloc is created like char and not like void? if we are going to work with different type of arrays? Here is de program: *This is a function that make a copy of any given array. * We then use this function make a...
c++ please read all question edit the program to test different random sizes of the array and give me the time in a file will be like random size of the array and next to it the time it took for each size Im trying to do time analysis for Quick sort but i keep getting time = 0 also i want edit the program to test different random sizes of the array and give me the time in a...