Search code examples
algorithmnumbersflowchart

An algorith that prints the largest of N numbers?


I'm just starting programming and I need help on our first assignment in our course. The assignment is: "Given N, write an algorithm that prints the largest of N numbers." What does the instructor mean by "the largest of N numbers"? Is "N" a number?

Sorry for such a beginner question.

Thank you very much in advance!

Note: The algorithm should be made in flowchart form.


Solution

  • Given N numbers, write an algorithm to find the largest. That's easy to implement using an array of size N that holds all numbers and a variable that holds the largest number.

    Try do it yourself before your read on...

    Initialise the variable to zero and iterate through the elements of the array comparing each element to the variable. If the element is grater than the variable, set the variable to the element. When you finished iterating all elements in the array, the variable should contain the largest number in the set of N numbers.