One way to find the maximum of n numbers is to initialize a variable to store the maximum value, then iterate through the n numbers. During each iteration, compare the current number to the stored maximum value, updating the maximum if the current number is greater. After iterating through all n numbers, the variable will contain the maximum value. This algorithm has a time complexity of O(n) as it requires iterating through all n numbers once.
Chat with our AI personalities
#include void main()
{
int a[10] = { 4, 55, 65, 73, 87, 99, 45, 454, 4353, 243}; int i, j, k, l; for ( j = 9, i = 1, k = 5, l = 6; i <= 2, k >= 3, l<= 7, j >= 8 ; i++, j--, k--, l++)
{
if (a[0] < a[i])
{
a[0] = a[i];
}
if (a[0] < a[j])
{
a[0] = a[j];
}
if (a[0] < a[k])
{
a[0] = a[k];
}
if (a[0] < a[l])
{
a[0] = a[l];
}
} printf("highest number = %d", a[0] );
}
Given a set of n numbers, to find the largest is a simple matter. Iterate through the numbers with a controlled loop structure using a maxValue variable. If the next variable is greater than maxValue, then that variable is the new maxValue. This continues until there are no more variables. Once that occurs, maxValue will have the largest number in the set of n numbers.
In Java
// returns largest number in nums; or 0 if nums is empty
int findLargest(int[] nums) {
if(nums.length == 0) {
return 0;
}
int max = nums[0];
for(int i = 1; i < nums.length; ++i) {
if( nums[i] > max ) {
max= nums[i];
}
}
return max;
}
You need to save all your numbers in array nums[array_size] of type double (int if you like it more). Then you define function max(nums, array_size) which takes the array and its length as arguments. Thus you have:
double max(nums, array_size)
{
double maximum = nums[0];
for (int i = 0; i < array_size, i++)
{
if (maximum < nums[i])
{
maximum = nums[i];
}
}
return maximum;
}
To find the maximum number in an array, assume the first number is the largest and store it. Then compare this stored value with all other values in the array, updating the stored value each time a larger value is found. Once all values have been tested, the stored value is the largest in the array.
jgfujtf
huh?
Write an. Algorthim. To. Find the. Sum. Of. First15 natural. Numbers
Perform encryption on the following PT using RSA and find the CT p = 3; q = 11; M = 5
(defun max3 (a b c) (cond ((> a b) (cond ((> a c) a) (t c))) ((> b c) b) (t c) ) )