My Math Forum

My Math Forum (http://mymathforum.com/math-forums.php)
-   Applied Math (http://mymathforum.com/applied-math/)
-   -   Largest and Smallest Decimal Number Computer program. (http://mymathforum.com/applied-math/339617-largest-smallest-decimal-number-computer-program.html)

prashantakerkar March 20th, 2017 09:35 AM

Largest and Smallest Decimal Number Computer program.
 
Can we write a computer program which will find the largest and Smallest Decimal Number in a List?

Example: 3.2,4.3,-2.1,7.3,5.4,-6.3,8.2,1.1,0.8

Thanks & Regards,
Prashant S Akerkar

Maschke March 20th, 2017 09:49 AM

Yes, that's a pretty straightforward beginning programming exercise.

Yooklid March 21st, 2017 10:43 AM

You need to define what you mean by largest and smallest. If smallest is most negative then:

In Excel:
Max( 3.2,4.3,-2.1,7.3,5.4,-6.3,8.2,1.1,0.8 )

and

Min( 3.2,4.3,-2.1,7.3,5.4,-6.3,8.2,1.1,0.8 )

If smallest means closest to zero, then it becomes marginally more complicated.

prashantakerkar March 21st, 2017 10:31 PM

Thanks.

Output of the Computer program should be :

Largest Decimal Number : 8.2
Smallest Decimal Number : -6.3

Can this be achieved?

Thanks & Regards,
Prashant S Akerkar

Country Boy March 31st, 2017 05:28 AM

In what computer language? As Yooklid said, excel has built in functions that do that automatically. If you are asking for a program that uses only the most simple commands then start by setting "max" and "min" equal to a number in the list. Then loop through the list, comparing each number to "max" and "min". If the number is larger than "max", set "max" equal to it. If the number is less than "min", set min equal to it.

Suppose your list of numbers is the array "numbers[]" with n members. Then

float max, min;
max= min= numbers[0];
for (i=0;i< n;i++)
{
if (numbers[i]> max) then max= numbers[i];
if (numbers[i]< min) then min= numbers[i];
}

Benit13 March 31st, 2017 06:46 AM

Quote:

Originally Posted by prashantakerkar (Post 565000)
Thanks.

Output of the Computer program should be :

Largest Decimal Number : 8.2
Smallest Decimal Number : -6.3

Can this be achieved?

Thanks & Regards,
Prashant S Akerkar

Yes


All times are GMT -8. The time now is 09:51 PM.

Copyright © 2019 My Math Forum. All rights reserved.