answersLogoWhite

0


Best Answer

In C#: int[] list = new int[] { 1 , 2, 3, 4}; int highest = int.MinValue; foreach(int i in list) { if(i > highest) { highest = i; } } Console.WriteLine(highest.ToString() + " is the highest number");

User Avatar

Wiki User

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

Wiki User

11y ago

// Algorithm 1 public int largest(int a, int b, int c) {

int t = a;

if(t < b) {

t = b;

}

if(t < c) {

t = c;

}

return t;

}

// Algorithm 2

public int largest(int a, int b, int c) {

if(a > b && a > c) {

return a;

}

if(b > a && b > c) {

return b;

}

return c;

}

// Algorithm 3

public int largest(int a, int b, int c) {

return a > b ? a > c ? a : c : b > c ? b : c;

}

All three do the same thing, but illustrate different ways to accomplish the same ends. The first uses a temporary variable, the second one skips the temporary variable, while the third combines all the if statements into a chained ternary statement (not recommended for professional code, but included here for illustrative purposes).

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write an algorithm to find the greatest number out of the gioven four numbers?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Write an algorithm and draw a corresponding flowchart to find the greatest number and its position among the 6 given numbers?

Algorithm Step1: Read A, B, C Step2: If A &gt; B is True, then check whether A &gt; C, if yes then A is greatest otherwise C is greatest Step3: If A &gt; B is False, then check whether B &gt; C, if yes then B is greatest otherwise C is greatest Give the Flowchart Answer


What is algorithm in basic computer science?

An algorithm is a set of instructions that a computer follows, generally to accomplish one specific task. These tasks can range from sorting a set of numbers to finding the greatest common denominator of two numbers.


Write an algorithm and draw a corresponding flowchart to search a number in the given list of numbers and also display its position?

please give me an algorithm and a corresponding flow chart that displays list of numbers from 1 to 20.


How can you write an algorithm for getting autoformic numbers?

Perhaps you mean an automorphic number? Loop through a series of numbers - for example, all numbers from 1 to 10,000 - and check each of the numbers, whether the condition applies. The condition in this case is that if you square the number, the last digits represent the original number.


How do you sort an array of numbers?

Use a sorting algorithm. There are a bewildering number of sorting algorithms, both stable and unstable. To sort numbers, an unstable sort suffices. The algorithm you use will depend on how many numbers need to be sorted (a small or a large set), however a hybrid algorithm (a combination of two or more algorithms) can cater for both. Introsort (unstable) and timsort (stable) are the two most common hybrid sorting algorithms.

Related questions

What is the algorithm for adding negative numbers?

subtract the positive number


Write an algorithm to check whether a number is a prime number or not?

You can write out this algorithm. This will then be programmed into the device to make determining prime numbers easier.


Write an algorithm and draw a corresponding flowchart to find the greatest number and its position among the 6 given numbers?

Algorithm Step1: Read A, B, C Step2: If A &gt; B is True, then check whether A &gt; C, if yes then A is greatest otherwise C is greatest Step3: If A &gt; B is False, then check whether B &gt; C, if yes then B is greatest otherwise C is greatest Give the Flowchart Answer


Can you write an algorithm to find the greatest of three number using class?

Yes. But why?


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.)


What is the definition of algorithm?

The definition of the word algorithm is a set of rules for solving a problem in a finite number of steps, as for finding the greatest common divisor.


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 greatest common factor of 14 26 36 44 50 54 56?

Take the greatest common factor of the first two numbers - for example, using Euclid's algorithm. Then take the greatest common factor of the result, and the third number, etc.


What is algorithm in basic computer science?

An algorithm is a set of instructions that a computer follows, generally to accomplish one specific task. These tasks can range from sorting a set of numbers to finding the greatest common denominator of two numbers.


What is the greatest odd number?

There are an infinite amount of numbers, so there can be no "greatest" odd number.


Examples of Euclid's algorithm for finding GCD of large numbers?

Euclid's algorithm is a time-tested method for finding the greatest common divisor (GCD) of two numbers. It's based on the principle that the greatest common divisor of two numbers also divides their difference. This algorithm is efficient and works well for large numbers, making it a practical choice in numerous applications. The algorithm operates in a recursive or iterative manner, continually reducing the problem size until it reaches a base case. Here’s how Euclid's algorithm works: print (gcd (a, b) ) # Output: 3ere &gt;a&gt;b , subtract b from a. Replace a with (a−b). Repeat this process until a and b become equal, at which point, a (or b) is the GCD of the original numbers. A more efficient version of Euclid’s algorithm, known as the Division-based Euclidean Algorithm, operates as follows: Given two numbers a and b, where &gt;a&gt; b, find the remainder of a divided by b, denoted as r. Replace a with b and b with r. Repeat this process until b becomes zero. The non-zero remainder, a, is the GCD of the original numbers. In this example, even though a and b are large numbers, the algorithm quickly computes the GCD. The division-based version of Euclid’s algorithm is more efficient than the subtraction-based version, especially for large numbers, as it reduces the problem size more rapidly. Euclid's algorithm is a fundamental algorithm in number theory, with applications in various fields including cryptography, computer science, and engineering. Its efficiency and simplicity make it a powerful tool for computing the GCD, even for large numbers.


What is the greatest number that belongs to the sets of integers and rational numbers but not in natural and whole numbers?

the greatest number that is an integer and rational number but is not a natural or whole number is -1