Presentation is loading. Please wait.

Presentation is loading. Please wait.

Some Common Issues: Common Algorithms

Similar presentations


Presentation on theme: "Some Common Issues: Common Algorithms"— Presentation transcript:

1 Some Common Issues: Common Algorithms
Damian Gordon

2 Prime Numbers

3 # PROGRAM CheckPrime: a = int(input("Please input value:")) b = a - 1 IsPrime = True while b != 1: # DO if a % b == 0: # THEN IsPrime = False # ENDIF; b = b - 1 # ENDWHILE; if IsPrime: print(a, "is a prime number") else: print(a, "is not a prime number") # END.

4 7 A # PROGRAM CheckPrime: a = int(input("Please input value:")) b = a - 1 IsPrime = True while b != 1: # DO if a % b == 0: # THEN IsPrime = False # ENDIF; b = b - 1 # ENDWHILE; if IsPrime: print(a, "is a prime number") else: print(a, "is not a prime number") # END.

5 7 A 7/6 A/B 7/5 A/B 7/4 A/B 7/3 A/B 7/2 A/B
# PROGRAM CheckPrime: a = int(input("Please input value:")) b = a - 1 IsPrime = True while b != 1: # DO if a % b == 0: # THEN IsPrime = False # ENDIF; b = b - 1 # ENDWHILE; if IsPrime: print(a, "is a prime number") else: print(a, "is not a prime number") # END. 7/6 A/B 7/5 A/B 7/4 A/B 7/3 A/B 7/2 A/B

6 # PROGRAM CheckPrime: a = int(input("Please input value:")) b = a - 1 IsPrime = True while b != 1: # DO if a % b == 0: # THEN IsPrime = False # ENDIF; b = b - 1 # ENDWHILE; if IsPrime: print(a, "is a prime number") else: print(a, "is not a prime number") # END. Sentinel value

7 # PROGRAM CheckPrime: a = int(input("Please input value:")) b = a - 1 IsPrime = True while b != 1: # DO if a % b == 0: # THEN IsPrime = False # ENDIF; b = b - 1 # ENDWHILE; if IsPrime: print(a, "is a prime number") else: print(a, "is not a prime number") # END. Sentinel value

8 Fibonacci Numbers

9 # PROGRAM FibonacciNumbers: a = int(input("Please input value:")) FirstNum = 1 SecondNum = 1 while a != 1: # DO total = SecondNum + FirstNum FirstNum = SecondNum SecondNum = total a = a - 1 # ENDWHILE; print(total) # END.

10 + FirstNum SecondNum Total
# PROGRAM FibonacciNumbers: a = int(input("Please input value:")) FirstNum = 1 SecondNum = 1 while a != 1: # DO total = SecondNum + FirstNum FirstNum = SecondNum SecondNum = total a = a - 1 # ENDWHILE; print(total) # END. FirstNum + SecondNum Total

11 + FirstNum SecondNum Total
# PROGRAM FibonacciNumbers: a = int(input("Please input value:")) FirstNum = 1 SecondNum = 1 while a != 1: # DO total = SecondNum + FirstNum FirstNum = SecondNum SecondNum = total a = a - 1 # ENDWHILE; print(total) # END. FirstNum + SecondNum Total

12


Download ppt "Some Common Issues: Common Algorithms"

Similar presentations


Ads by Google