In mathematics and computer science, an algorithm is a step-by-step procedure for calculations. Algorithms are used for calculation, data processing, and automated reasoning. More precisely, an algorithm is an effective method expressed as a finite list of well-defined instructions for calculating a function. Starting from an initial state and initial input (perhaps empty), the instructions describe a computation that, when executed, will proceed through a finite number of well-defined successive states, eventually producing "output" and terminating at a final ending state. The transition from one state to the next is not necessarily deterministic; some algorithms, known as randomized algorithms, incorporate random input.
An algorithm to read five integers and find out if the values are in ascending order:
for i=0, i<5, i=i+1:
read a[i];
for i=1, i<5, i=i+1:
if a[i-1]>=a[i]
{
print "the values are not in ascending order";
exit;
}
print "the values are in ascending order";
exit;
Comments
Leave a comment