answersLogoWhite

0

** pseudo code ** if array length == 1, return first element else if array length > 1 max = first element for second item to last item if item > max max = item return max else // array length is 0 error

User Avatar

Wiki User

15y ago

Still curious? Ask our experts.

Chat with our AI personalities

BlakeBlake
As your older brother, I've been where you are—maybe not exactly, but close enough.
Chat with Blake
TaigaTaiga
Every great hero faces trials, and you—yes, YOU—are no exception!
Chat with Taiga
SteveSteve
Knowledge is a journey, you know? We'll get there.
Chat with Steve

Add your answer:

Earn +20 pts
Q: Find largest value algorithm in c?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Algorithm for calculating the average of 3 numbers?

AlgorithmStep1: Read A, B, CStep2: If A > B is True, then check whether A > C, if yes then A is greatest otherwise C is greatestStep3: If A > B is False, then check whether B > C, if yes then B is greatest otherwise C is greatestFollowing these steps flowchart can be made.


What a C function that will compute the K in largest and K in smallest element along with their positions in an array of N signed integers. Assume the following 5 N 50 and 1K?

To compute the largest value in an array, assume that the first element is the largest and store the value. Then traverse the remainder of the array. Each time a larger value is encountered, update the stored value. Once all values are traversed, return the stored value. In pseudocode, this algorithm would be implemented as follows: Algorithm: largest Input: array A of length N Output: largest value in A let largest = A[0] // store first value for index = 1 to N-1 // traverse remaining elements if A[index] > largest then largest = A[index] // update stored value if current value is larger next index return largest To determine the position of the largest value, we alter the algorithm as follows: Algorithm: largest_by_index Input: array A of length N Output: index of the largest value in A let largest = 0; // store index 0 for index = 1 to N-1 // traverse remaining elements if A[index] > A[largest] then largest = index // update stored index next index return largest We can do the same to find the position of the smallest element: Algorithm: smallest_by_index Input: array A of length N Output: index of the smallest value in A let smallest = 0; // store index 0 for index = 1 to N-1 // traverse remaining elements if A[index] < A[smallest] then smallest = index // update stored index next index return smallest To perform both algorithms simultaneously, we need to return two values. To achieve this we can use a simple data structure known as a pair: struct pair { int smallest; int largest; }; Algorithm: range_by_index Input: array A of length N Output: a pair indicating the position of the smallest and largest values in A pair result = {0, 0} // initialise the pair for index = 1 to N-1 // traverse remaining elements if A[index] < A[result.smallest] then result.smallest = index // update stored index else if A[index] > A[result.largest] then result.largest = index // update stored index next index return result


How can you implement Ricart and Agrawala's algorithm in c?

Ronaldo! 'c' coding of Ricart-agarwala algorithm


How do you RSA algorithm c?

Perform encryption on the following PT using RSA and find the CT p = 3; q = 11; M = 5


Write an algorithm to find the greatest number out of the gioven four numbers?

In C#: int[] list = new int[] { 1 , 2, 3, 4}; int highest = int.MinValue; foreach(int i in list) { if(i > highest) { highest = i; } } Console.WriteLine(highest.ToString() + " is the highest number");