Other Instructions Will Be Provided by The Instructor: Pseudo Code and Programming
Other Instructions Will Be Provided by The Instructor: Pseudo Code and Programming
for l in range(len(score)):
min = l
for i in range(l + 1, len(score)):
if score[i] < score[min]:
min = i
temp=score[l]
score[l]=score[min]
score[min]=temp
print("Scores less than 500:")
for j in range(len(score)):
if score[j] < s:
print(score[j])
print("Score greater than 500:")
for j in range(len(score)):
if score[j] > s:
print(score[j])
return(score)
score=[198,486,651,85,216,912,73,319,846,989]
s=500
selectionSort(score)
Pseudo Code:
Declare score as array
Declare s,i,l,j as integer
set n as length of array
for (l=0;l<n-1;l++)
min=l
for (i=l+1;i<n;i++):
if score[i]<score[min]
min=i
temp=score[l]
score[l]=score[min]
score[min]=temp
write score less than 500:
for (j=0;j<n;j++)
if score[j]>s
write score[j]
write score less than 500
for (j=0;j<n;j++)
if score[j]<s
write score[j]
selectionSort(score)
Question 2: Programming
Write a program to load an array, Squares, with 100 numbers. Each element should contain the
square of its index value. In other words, Squares[0] = 0, Squares[3] = 9, Squares[8] = 64, and so
on. Then prompt the user for a number from 0 through 1000 and write pseudocode to check if
that number is a perfect square (i.e., if the user inputs X, check to see if X is a value in the
array). Use a serial search for this program.
Answer:
count = 0
arr = []
index = 0
for i in range(100):
arr.append(i*i)
n = int(input("Enter a number from 0 through 1000:\n"))
while(count == 0) and (index < 100):
if n == arr[index]:
count = 1
break
index += 1
if(n >= 0) and (n <= 1000):
if count == 1:
print("Number ",n," is a perfect square")
else:
print("Number ",n," not a perfect square")
else:
print("Number is out of range")
Pseudo Code: