int[] nums; // assume this is an array of length 5 and you want to find the largest
// finding it with a loop
int max = nums[0];
for(int i = 1; i < nums.length; ++i) {
if(nums[i] > max) {
max = nums[i];
}
}
// max is now the largest
// finding it manually
int max = Math.max(nums[0], Math.max(nums[1], Math.max(nums[2], Math.max(nums[3], nums[4]))));
// ugly, but effective
//Save this as gnum.java
public class gnum
{
double[] nums= {37,23,43,6.7,56}; //edit the numbers here to use different values
public static void main(Strings, args[])
{
System.out.print(getHighest());
}
public static double getHighest()
{
double highest = -999999999;
for (int x=0;x<5;x++)
{
if ( nums[x] > highest)
highest = x
}
return highest;
}
}
Assume that the first number is the maximum (store it to a variable called, for example, "maximum"). Loop through the array; every time you find an array element (a number) that is larger than the previous maximum, replace variable "maximum" with this number.
system.out.print(Math.max(x, Math.max(y,z)))
int findMax(int *array) { int max = array[0]; for(int i = 1; i < array.length(); i++) { if(array[i] > max) max = array[i] } return max; }
maxValue = function (array) {mxm = array[0];for (i=0; i<array.length; i++) {if (array[i]>mxm) {mxm = array[i];}}return mxm;}; i don't know
i want to write a simple without using pointer or array c program which will print greatest number when i give 20 number .........How far have you gotten so far?
int max(int arr[], int arrSize){int maximum = arr[0];for (int i = 0; i < arrSize; i++){if (maximum < arr[i]){maximum = arr;}}return maximum;}
Reference:cprogramming-bd.com/c_page1.aspx# array programming
int findMax(int *array) { int max = array[0]; for(int i = 1; i < array.length(); i++) { if(array[i] > max) max = array[i] } return max; }
maxValue = function (array) {mxm = array[0];for (i=0; i<array.length; i++) {if (array[i]>mxm) {mxm = array[i];}}return mxm;}; i don't know
i want to write a simple without using pointer or array c program which will print greatest number when i give 20 number .........How far have you gotten so far?
int max(int arr[], int arrSize){int maximum = arr[0];for (int i = 0; i < arrSize; i++){if (maximum < arr[i]){maximum = arr;}}return maximum;}
Reference:cprogramming-bd.com/c_page1.aspx# array programming
How to write a program for mouse in microprocessor?
To write a C++ program to display the student details using class and array of object.
You can write a C++ fib pro using arrays but the problem is the prog becomes very complicated since u need to pass the next adding value in an array.....
write an assembly language program to find sum of N numbers
array type
public static int[] reverseArray(int[] array) { int i = 0, j = array.length - 1; for (i = 0; i < array.length / 2; i++, j--) { int temp = array[i]; array[i] = array[j]; array[j] = temp; } return array; }
You need to specify the language in which you want the subtraction of the two matrix in two dimension array written.