Вы находитесь на странице: 1из 4

1. Find the largest element in a finite set.

1. Display to the user: “INPUT 5 NUMBERS”, and the user must input 5
numbers.

2. Set the tempVar variable (int data type) equal to the first integer inputted
by the user.

3. Compare the next integer in the sequence to the tempVar, and if it is


larger than the tempVar variable: set the tempVar's value equal to the larger
integer.

4. Repeat the previous step and stop when there are no integers left in the
sequence. The tempVar variable at this point is the largest integer in the set.

5. Display to the user the value of the tempVar variable.

Sample Output:
2. An algorithm that reverse the sequence (From lowest to highest)

Sort numbers in Ascending Order:

1. Display to the user: “INPUT 5 NUMBERS”, and the user must input 5 numbers.

2. Set the tempVar variable (int data type) equal to the first integer inputted by the user.

3. Display to the user: “NUMBERS IN ASCENDING ORDER:”.

4. Compare the next integer in the sequence to the tempVar, and if it is larger than the
tempVar variable: set the tempVar's value equal to the larger integer and display it to the
user afterwards.

5. Repeat the previous step and stop when there are no numbers left to compare to.

6. At this point, the result will be displayed to the user in ascending order.

Sample Output:

Sort numbers in descending order:


1. Display to the user: “INPUT 5 NUMBERS”, and the user must input 5 numbers.

2. Set the tempVar variable (int data type) equal to the first integer inputted by the user.

3. Display to the user: “NUMBERS IN DESCENDING ORDER:”.

4. Compare the next integer in the sequence to the tempVar, and if it is smaller than the
tempVar variable: set the tempVar's value equal to the smaller integer and display it to
the user afterwards.

5. Repeat the previous step and stop when there are no numbers left to compare to.

6. At this point, the result will be displayed to the user in descending order.

Sample Output
3. Compute the Greatest Common Divisor (Using Euclidean Algorithm).

1. Display “INPUT TWO NUMBERS:”, and the user must then input two
numbers (The 1st number must be larger than the 2nd number).

2. Divide the two numbers and get the result, and the remainder. (A ÷ B = C
with remainder R).

3. Replace A with B, then replace B with R, then divide it again.

4. Repeat step 2 until the remainder is equals to 0 (R = 0).

5. When R = 0, the divisor, will be the Greatest Common Divisor (GCD).

6. Display the result to the user.


Sample Output:

Computation:

Вам также может понравиться