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.
The largest and the smallest of a given number must be itself, since there is only one 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.
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 }
1
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.
hello people
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.
1,000000000000,00000000000000,00000000,000000000000,00000000000,00000000000,00000,0000000000,000000,actually, there is no such thing as 'the largest number'.
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 }
Smallest number
The smallest is 11 and the largest is 97.
Smallest = 94999.5 Largest = 95000.5
The smallest number is 5000 while largest number is 14999.
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
The smallest is 11 and the largest is 97.
0
The smallest number is zero. The largest number is 63.
10,000,000 is the smallest 8 digit number 99,999,999 is the largest 8 digit number