int secondmax (int a[], int n)
{
int i, max, second;
for (i=0; i if (i==0 a[i]>max) second= max, max= a[i]; else if (i==1 a[i]>second) second= a[1]; } return second; } int middle (int a[3]) { return secondmax (a, 3); }
what is algorithm and its use there and analyze an algorithm
It is an algorithm used by another algorithm as part of the second algorithm's operation.As an example, an algorithm for finding the median value in a list of numbers might include sorting the numbers as a sub-algorithm: There are plenty of algorithms for sorting, and the specifics of the sorting does not matter to the "median value" algorithm, only that the numbers are sorted when the sub-algorithm is done.For what an algorithm is, see related link.
To sort three numbers in ascending order, you can use a simple comparison-based algorithm. First, compare the first two numbers and swap them if the first is greater than the second. Then, compare the second number with the third and swap if necessary. Finally, check the first number against the second again to ensure they are in order. This process will yield the numbers in ascending order.
write an algorithm to compute the weekly average rainfall given the daily rainfall for four weeks
All algorithms have a best, worst and average case. Algorithms that always perform in constant time have a best, worst and average of O(1).
Algorithm to find the sum and average of 3 numbers: Start. Input three numbers (let's call them A, B, and C). Calculate the sum (Sum = A + B + C). Calculate the average (Average = Sum / 3). Output the sum and average. End. Flowchart: [Start] ↓ [Input A, B, C] ↓ [Sum = A + B + C] ↓ [Average = Sum / 3] ↓ [Output Sum, Average] ↓ [End]
By dividing
Describe an algorithm for dividing rational numbers.
1.Start Algorithm 2.Enter first number 3.Enter second number 4.Enter third number 5.Enter fourth number 6.Enter fifth number 7.Add five number 8.display five number / 2 9.Display result 10.End Algorithm
You can use Euclid's algorithm to calculate the gcf of two of the numbers - then use Euclid's algorithm again with the result and the third number.Or you can factor all the numbers into prime factors, and check which prime factors occur in all three numbers.
To calculate the average of two numbers, add them together, and divide the result by 2. (For the average of three numbers, you add up the three numbers, and divide by three, etc.) The average is (5000 + 7000)/2 = 6000
125, 126 and 127.
To calculate the total and average using an algorithm, first, iterate through a collection of numbers and sum them up to get the total. Then, divide the total by the count of numbers in the collection to find the average. The algorithm can be outlined as follows: initialize a total variable to zero, loop through each number to add it to the total, and finally divide the total by the number of elements to get the average. This process can be implemented in various programming languages using loops and basic arithmetic operations.
Yes. For example, the average of 5, 7, and 9 is 7.
3, 5, and 7 are three prime numbers whose average is 5.
The average of the numbers 51, 52, and 56 is 53. To get the average you would add all three numbers and then divide by three.
12