cs
cs
loop I from 0 to 4
SAMPLE[I] = input("Enter the measurement")
end loop
loop I from 0 to 3
if SAMPLE[I] > SAMPLE[I+1] then
SORTEDA = 0
end if
if SAMPLE[I] < SAMPLE[I+1] then
SORTEDD = 0
end if
end loop
output "The array is:"
loop I from 0 to 4
output SAMPLE[I]
end loop
if SORTEDA = 1 then
output "The array is sorted in ASCENDING order"
else
output "The array is not sorted in ASCENDING order"
end if
if SORTEDD = 1 then
output "The array is sorted in DESCENDING order"
else
output "The array is not sorted in DESCENDING order"
end if
Explanation:
Takes 5 user inputs and stores them in an array.
Checks whether the array is sorted in ascending or descending order.
Prints the appropriate message based on the detected order.
4. Linear Search (Finding a Value in an Array)
Pseudocode:
Declare ARRAY[10]
Declare Integer SEARCHVALUE
Input SEARCHVALUE
Found = False
loop I from 0 to 9
if ARRAY[I] = SEARCHVALUE then
Found = True
output "Value found at index ", I
end if
end loop