1,Write a function named twomax that takes a pointer to an array of integer numbers, array size, a pointer to integer which is the index of the first maximum, and another pointer to integer which is the index of the second maximum as parameters. The function should find and return the index (subscript or position) of the first maximum element and the index of the second maximum element in the array of integers. The function prototype is: void twomax(int *array,int size,int * p1,int *p2); write a main to test twomax function. 2,Write a program that asks the user to enter names of students and store them in an array of strings. Define a pointer that pointed to the array. The program should stop accepting the names when the name entered is” 999”. After that, the program should ask the user to enter a character and then the program should print all the names that start with the entered character. The maximum number of students is 100. Use the pointer to access the array elements.

1. Introduction

In this task, we are required to write a function named “twomax” that takes a pointer to an array of integer numbers, the array size, a pointer to the index of the first maximum, and another pointer to the index of the second maximum as parameters. The function should find and return the index of the first maximum element and the index of the second maximum element in the array of integers. Additionally, we are asked to write a main function to test the “twomax” function.

1.1 Function Prototype

The given function prototype for the “twomax” function is as follows:

void twomax(int *array, int size, int *p1, int *p2);

Here, “array” is a pointer to an array of integer numbers, “size” represents the size of the array, and “p1” and “p2” are pointers to integers that will store the indices of the first and second maximum elements.

2. Implementation of the “twomax” function

To implement the “twomax” function, we can use a simple algorithm. We initialize the first maximum index as 0 and the second maximum index as -1. Then, we iterate through the array of integers and update the maximum and second maximum indices accordingly. Finally, we assign the values of maximum and second maximum indices to the pointers “p1” and “p2”.

Pseudocode for the “twomax” function:

1. Initialize maxIndex = 0, secondMaxIndex = -1
2. For i = 1 to size
a. If array[i] > array[maxIndex]
i. Set secondMaxIndex = maxIndex
ii. Set maxIndex = i
b. Else if array[i] > array[secondMaxIndex] (after checking the above condition)
Set secondMaxIndex = i
3. Assign maxIndex to *p1 and secondMaxIndex to *p2

3. Testing the “twomax” function

To test the “twomax” function, we need to write a main function. In the main function, we can first initialize an array of integers and its size. Then, we can call the “twomax” function with the array, size, and appropriate pointers for storing the indices of the first and second maximum elements. Finally, we can print the returned indices to verify the correctness of our implementation.

Pseudocode for the main function:

1. Initialize array of integers, size, and variables p1, p2
2. Call twomax(&array, size, &p1, &p2)
3. Print p1 and p2 (indices of first and second maximum elements)

By following the above steps, we can successfully implement and test the “twomax” function and the main function. This will allow us to find and return the indices of the first and second maximum elements in an array of integers.

Need your ASSIGNMENT done? Use our paper writing service to score better and meet your deadline.


Click Here to Make an Order Click Here to Hire a Writer