answersLogoWhite

0


Best Answer

To find the largest number: Assume (temporarily) that the first number is the largest number. You might call this the "largest number found so far". Then, for each number after the first one, compare the number with the largest number found so far. If the new number in the list is larger, call that one the "largest number found so far". Repeat for each number. After processing all the numbers, the "largest number found so far" will simply be the largest number.For example, if your list is (5, 2, 8, -1), you start assuming that 5 (the first number in the list) is the largest number. You compare with 2 - "5" is still the largest number, since 2 is smaller. When you compare with 8, you find that 8 is larger, so you replace your "largest number" with 8. "-1" is smaller, so nothing changes. Since we processed the entire list, the largest number is now 8.
You can do the same - mutatis mutandis - to find the smallest number.

User Avatar

Wiki User

8y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

8y ago

The largest and the smallest of a given number must be itself, since there is only one number.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the algorithm for finding largest and smallest of given number?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

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.


Write algorithm of a largest number in three numbers?

1. Read the 3 nos a,b,c 2. Let larget = a 3. if b > largest then largest = b 4. if c > largest then largest = c..... If you have to process more nos, read all of them in an array. Assume the first element be largest, do comparison through all elements of the array.... Similar algorithm can be developed for finding the lowest also. /*lab practice 2 damithguruge question 4 */ #include<stdio.h> int main() { int num1,num2,num3,num4; int smallest; printf("Please enter a number1"); scanf("%d%*c", &num1); printf("Please enter a number2"); scanf("%d%*c" ,&num2); printf("Please enter a number3"); scanf("%d%*c", &num3); Printf("Please enter a numbe4r"); scanf("%d%*c", &num4); /* num1 set as the smallest */ smallest=num1; if(smallest > num2) then smallest=num2; else if smallest >num3 then smallest=num3; else if smallest>num4 then smallest=num4; printf("smallest number:%d\n,smallest"); return(0); endif endif endif }


How do you write the 8051 micro controller alp for finding the largest number in an array?

1


What are the characteristics of an algorithm. Describe with an example?

An algorithm is a stepwise sequence of operations that can be performed to solve a problem. The operations are expected to be 'simple', so they can be performed mechanically.A simple example algorithm is "how to find the largest number in a list of numbers":- look at the first number and write it down as the largest-so-far- for each remaining number in the list:- - replace largest-so-far with this number if this number is larger- when you have compared all the numbers, largest-so-far is the largest number in the listA less trivial algorithm is the one people learn in school for multiplying multi-digit numbers, called "long multiplication" or "grade-school multiplication". It becomes rather long if you write down all the steps (as you would need to for an algorithmic description), but it involves multiplying each digit in the first number with each digit in the second number and summing the partial results.Here the simple operation is multiplying two single digits, which you are expected to know how to do, and by using the algorithm you can extend the knowledge of how to multiply single digits to multiply numbers with any number of digits.See related links.


What are the six regions based largest to smallest based on the number of states in ech region?

hello people

Related questions

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 i find an algorithm to determine the largest number?

1,000000000000,00000000000000,00000000,000000000000,00000000000,00000000000,00000,0000000000,000000,actually, there is no such thing as 'the largest number'.


Write algorithm of a largest number in three numbers?

1. Read the 3 nos a,b,c 2. Let larget = a 3. if b > largest then largest = b 4. if c > largest then largest = c..... If you have to process more nos, read all of them in an array. Assume the first element be largest, do comparison through all elements of the array.... Similar algorithm can be developed for finding the lowest also. /*lab practice 2 damithguruge question 4 */ #include<stdio.h> int main() { int num1,num2,num3,num4; int smallest; printf("Please enter a number1"); scanf("%d%*c", &num1); printf("Please enter a number2"); scanf("%d%*c" ,&num2); printf("Please enter a number3"); scanf("%d%*c", &num3); Printf("Please enter a numbe4r"); scanf("%d%*c", &num4); /* num1 set as the smallest */ smallest=num1; if(smallest > num2) then smallest=num2; else if smallest >num3 then smallest=num3; else if smallest>num4 then smallest=num4; printf("smallest number:%d\n,smallest"); return(0); endif endif endif }


Is negative infinity the largest or smallest number?

Smallest number


What is the smallest and the largest 2 digit number?

The smallest is 11 and the largest is 97.


What is the answer of smallest and largest if whole number is 95000?

Smallest = 94999.5 Largest = 95000.5


What is largest and smallest numbers that round off to 10000?

The smallest number is 5000 while largest number is 14999.


How to find the range of numbers?

Subtract the smallest number from the largest number and you will get the distance from the smallest number to the largest number. That is the range. Ex: {-2 -4 -6 3 6 7 12} Smallest number is -6, largest number is 12. 12- (-6) = 12 + 6 = 18. The distance from the smallest number to the largest is 16


What is the smallest and largest two digit prime number?

The smallest is 11 and the largest is 97.


What is the 3-digit largest number and 3-digit smallest number without repetition?

0


What is the smallest number that can be represented with 6 bits?

The smallest number is zero. The largest number is 63.


Smallest eight digit number to the largest eight digit number?

10,000,000 is the smallest 8 digit number 99,999,999 is the largest 8 digit number