answersLogoWhite

0


Best Answer

Algorithm
Step1: Read A, B, C
Step2: If A > B is True, then check whether A > C, if yes then A is greatest otherwise C is greatest
Step3: If A > B is False, then check whether B > C, if yes then B is greatest otherwise C is greatest

Following these steps flowchart can be made.

User Avatar

Wiki User

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

Wiki User

14y ago

Pseudo-code:

Made a variable to hold the largest number.

Assume the largest number is the first one. Assign number to variable.

Go to next number. If it is greater, assign the new number to variable.

Continue until you run out of numbers.

Java:

int[] arr = {2, 10, -2}; // Array of numbers

int max = arr[0]; // assume the max is the first number

for(int k = 1; k < arr.length; k++) // traverse starting with the second element

{

if( arr [k] > max) // if the value checked is greater than my current max

max = arr[k]; // reassign my max

}

C++:

I totally did not steal and make minor changes to this code to make it work in C from anyone...

int arr[] = {2, 10, -2}; // Array of numbers

int max = arr[0]; // assume the max is the first number

for(int k = 1; k < 3; k++) // traverse starting with the second element

{

if( arr [k] > max) // if the value checked is greater than my current max

max = arr[k]; // reassign my max

}

Edit: Here's a more efficient c++ method from luke s.

for(int i=0;i<=2;i++){

cout << "Enter number " << i+1 << ": ";

cin >> num[i];

if(num[i]>num[i-1]){high=num[i];}

}

This answer is:
User Avatar

User Avatar

Wiki User

9y ago

The simplest algorithm employs a function to find the largest of two values. The return value can then be input to the same function along with the third value to determine the largest of three values:

// return largest of 2 values

int max(int a, int b) {return a<b?b:a;}

// return largest of 3 values

int max(int a, int b, int c) {return max(max(a,b),c);}

The function can be overloaded to cater for any number of values simply by calling the previous overload:

// return largest of 4 values

int max(int a, int b, int c, int d) {return max(max(a,b,c),d);}

Although you can provide as many overloads as desired, it would be simpler to use an overload that accepts a vector of values:

int max(std::vector<int>& v)

{

if (v.empty())

throw std::range_error("max(std::vector<int>&): range error!");

int m = v[0];

for (size_t i=1; i<v.size(); ++i) m=max(m,v[i]);

return m;

}

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

It is hard. Very hard. Actually, it requires a genius.

avg = (x+y+z)/3

could also be

1.) Start

2.) Detrmine the first number; call it A

3.) Detrmine the second number; call it B

4.) Detrmine the third number; call it C

5.) Detrmine the number if integers; call it D

6.) Find the sum of A,B and C; call it X

7.) Divide X by D; call it the RESULT

8.) Present the RESULT

9.) Stop

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

Algorithm to find the largest of three numbers

Compare the first two numbers to find the larger of the two. Then compare the larger number with the third number to find the largest of all three.

Expressing this algorithm as a simple function in C:

int Largest( int num1, int num2, int num3 ){

return( num1 > num2 ? ( num1 > num3 ? num1 : num3 ) : ( num2 > num3 ? num2 : num3 ));

}

This answer is:
User Avatar

User Avatar

Wiki User

7y ago

To find the largest of three numbers you first need to find the largest of two numbers. That algorithm is extremely trivial:

Algorithm: largest_of_two

Input: two numeric values, a and b

Output: the value of a or b, whichever is the largest

if a > b then

return a

else

return b

Having established the largest of two, we can use this algorithm to establish the largest of three:

Algorithm: largest_of_three

Input: three numeric values, a, b and c

Output: the value of a, b or c, whichever is the largest

return largest_of_two (largest_of_two (a, b), c)

We could extend the algorithm to cater for any number of values, however there is a much simpler approach. First, place all the values in a container such as an array. Store the first value then compare all other values with the stored value. If the current value is larger, replace the stored value with the current value. When all values have been compared, the stored value holds the largest value.

Algorithm: largest_of_many

Input: an array of values, A

Output: the largest value in A

store := A[0] // store the first value

for i = 1 to size(A) - 1 // loop through all remaining values

if A[i] > store then store := A[i] // if the current value is larger, store it

end for

return store

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

write a programto enter five numbers through keyboard and find

average of then using array.

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

Simply find an algorithm for calculating the greatest of 2 numbers; and use it twice:

max3 (x,y,z) = max2 (max2 (x,y), z)

This answer is:
User Avatar

User Avatar

Wiki User

6y ago

To find the average of n numbers, sum the numbers and divide the sum by n. Thus for 4 numbers, divide their sum by 4.

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

Use a pen or a pencil.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Algorithm for calculating the average of 3 numbers?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What does calculate the average mean?

Calculating the average of a set of data is the same as calculating the mean, or the value that is in the middle of the data. For example, if you were given the numbers 3, 7, 10, 4, and 5, and was asked to find the average, this is how it would be done:First, add up all the numbers. 3 + 7 + 10 + 4 + 5 = 29Then, divide the added numbers by how many numbers there are, total, which is 5. 29/5 = 5.8The average of 3, 4, 5, 7, and 10, is 5.8.


How to write an algorithm that accepts five numbers and displays the sum and average of the numbers?

1.Start Algorithm 2.Enter first number 3.Enter second number 4.Enter third number 5.Enter fourth number 6.Enter fifth number 7.Add five number 8.display five number / 2 9.Display result 10.End Algorithm


What is the algorithm for average of three numbers?

int secondmax (int a[], int n){int i, max, second;for (i=0; imax) second= max, max= a[i];else if (i==1 a[i]>second) second= a[1];}return second;}int middle (int a[3]){return secondmax (a, 3);}


How do you calculates average?

add all the outcome / example 15, 64, 21, 7, 10, 3 = 120. Then divide the sum of all the numbers by the number of numbers/ example, take 120 divided by 6=20. So the average number out of all the numbers above is 20.


How do you average a math question?

To get the simple average of a series of numbers, you add the numbers up and divide by however many numbers there were. For example, the average of 2, 3 and 4 is the sum of the numbers (which adds up to 9) divided by 3 (because there are three numbers). So the average is 9/3 = 3.


If The average of 5 numbers is 6 and the average of 3 numbers is 4 find out the average of remaining two numbers?

2


Is there an algorithm that yields only prime numbers?

What exactly do you mean "yields only prime numbers"? If you mean a formula that when given the numbers n=1, 2, 3, ... and so on generates the nth prime number (or a different prime number for each n) then no. If you mean an algorithm whereby a number can be tested to be a prime number then yes. (Using this prime_test algorithm, a simple algorithm can be written that would supply numbers one at a time to it and use its result to decide whether to yield the tested number or not, only yielding those numbers which pass the test.)


Can the average of 3 numbers be one of those 3 numbers?

Yes. For example, the average of the numbers 1, 2, and 3 is 2. 1+2+3=6 6/3=2


How is multiplying by a 3 digit numbers similar to multiplying by a 2 digit number?

6


What is the algorithm of LCM of more than 3 numbers?

If you use methods based on prime factors, it is the same whether you have 2, 3, or more numbers: find all the factors that occur in any of your numbers. If you use a method based on Euclid's Algorithm (that is, lcm(a, b) = a x b / gcf(a, b), where you find the gcf with Euclid's Algorithm), then you can find the lcm for two numbers at a time. For example, to get the lcm of four numbers, find the lcm of the first two, then the lcm of the result and the third number, than the lcm of the result and the fourth number.


What is the average of 3 3.5 and 6?

The average of several numbers is the sum of the numbers divided by the quantity of the numbers. (3 + 3.5 + 6) &Atilde;&middot; 3 = 4 1/6


Finding the average the 3 numbers?

Add the 3 numbers together and divide that answer by 3. Example: The average of 2, 4, and 9. Average = (2+4+9)/3 = 15/3 =5.