Answer:
1 for i = 1 to A.length
2 if A[i] = nu
3 return i
4 return NIL
Explanation:
Loop invariant:
At the start of each iteration of the for loop of lines 1-3, there is no j<i such that A[j]=ν.
Initialization:
At the beginning of the first iteration, we have i=1, so there is no j<i such that A[j]=ν.
Maintenance:
We fix i and assume there is no j<i such that A[j]=ν.
If A[i]=ν, then we return a value, so then there are no more iterations, so the property is preserved.
If A[i]≠ν, then there is no j<i+1 such that A[j]=ν, which is the desired property for the next step.
Termination:
The loop terminates either for i=A.length+1, or if ever we encounter A[i]=ν.
In the first case, then there is no 1≤j≤A.length such that A[j]=ν, and we are correctly returning NIL
In the second case, if we encounter some i such that A[i]=ν, we are correctly returning i.
c. would be the best answer.
Limited access to a document usually means that the creator of the document is able to limit how much access one person is able to get.
Answer:
Answer:
def main():
num = int(input("Input a number to check for prime: "))
if num > 1:
for i in range(2,num):
if (num % i) == 0:
print("%d is not a prime number" % num)
break
else:
print("%d is a prime number" % num)
break
else:
print("%d is not a prime number" % num)
if __name__ == "__main__":
main()
Explanation:
Solution retrieved from programiz.com.
Note, this program uses the idea of the Sieve of Eratosthenes to validate the input number by using the modulo operator to determine primeness.
The program will output to the user if the number input is indeed prime or not.
Cheers.
Explanation:
I don't really understand the meaning of the question. Can you reply and i'll try to help...