answersLogoWhite

0

final double[] ns = new double[10];

final Random rnd = new Random(System.currentTimeMillis());

// Fill...

for (int i = 0; i < ns.length; ++i) {

ns[i] = rnd.nextDouble();

}

// Get largest/smallest...

double largest = Double.MIN_VALUE;

double smallest = Double.MAX_VALUE;

for (double n : ns) {

if (n > largest) {

largest = n;

}

if (n < smallest) {

smallest = n;

}

}

// largest and smallest are now the proper values.

User Avatar

Wiki User

15y ago

What else can I help you with?

Related Questions

C program to find the largest and smallest character in a word?

helicopter


How to write a C program for left factoring?

Name two variables x and y. Divide the largest by smallest. If remainder is zero then the smallest is the HCF.


How do you write program to read a set of real numbers and find the range is given by the difference between largest and smallest number?

Use the following algorithm (written in pseudocode). Let largest be the lowest possible real number. Let smallest be the greatest possible real number. Repeat while there is input... { Read real number r from input. If r is greater than largest then let largest be r. If r is less than smallest then let smallest be r. } End repeat. Let range be largest minus smallest. Output range.


How can you download c compiler?

write a c program to fine largest/smallest of 3no (using ?:ternary operator/conditional operator)


Write a program that will find the smallest largest and average values in a collection of N numbers Get the value of N before scanning each value in the collection of N numbers?

#include #include #include int main(int argc, char *argv[]){int n, smallest, largest, sum, temp;if(argc < 2){printf("Syntax: foo val1[val2 [val3 [...]]]\n");exit(1);}smallest = largest = sum = atoi(argv[1]);for(n = 2; n < argc; n++){temp = atoi(argv[n]);if(temp < smallest) smallest = temp;if(temp > largest) largest = temp;sum += temp;}printf("Smallest: %i\nLargest: %i\nAverage: %i\n", smallest, largest, sum / (argc - 1));return 0;}


Which component of a computer system executes the program and how?

C.p.u. Executes the program


Which component executes program instructions?

The CPU executes program instructions.


What is a token in the context of a C program?

smallest individual units of a program


What program covers the health component of the safety and health management system?

The Industrial Hygiene program covers the health component of the safety and health management system.


What program is an email component of windows vista?

donno


What is component testing in software testing?

Testing a specific part of a system or even a program. That would be called a component. So it is component testing.


What is tarp funding?

The Troubled Asset Relief Program (TARP) is a program of the United States government to purchase assets and equity from financial institutions in order to strengthen the financial sector. It is the largest component of the government's measures in 2008 to address the subprime mortgage crisis.