Problem 4: Great Common Divisor (gcd):
Using
Euclid's Algorithm,
You are to write an Ada procedure that computes the gcd of two positive integers. The program
should allow the user to compute as many gcds as desired and only stops when two
zeros (0 0) are encountered.
Example of execution:
******************************
********* GCD ****************
******************************
Enter two positive integers :
5 7 --> gcd(5,7) = 1.
Enter two postive integers :
6 12 --> gcd(6,12) = 6.
Enter two postive integers :
45 20 --> gcd(45,20) = 5.
Enter two positive integers :
0 12
Done *************************
Problem 5 : Divisors :
Write an Ada program that reads a positive integer then lists its positive divisors.
Bonus : How can you make your program run faster ?
Example of execution:
******************************
********* Divisors************
******************************
Enter a positive integer : 60
The divisors of 60 are : 1 2 3 4 5 6 10 12 15 20 30.
Problem 6 : Prime Numbers :
Prime numbers are very remarkable in integer arithmetic. A number is prime if its
positive divisors are 1 and the number itself. Example of prime numbers are : 2,3,5,7,11...
The set of prime numbers is infinite and that's why, in this problem, we won't try to find
all prime numbers. Specifically, you are to write an Ada program that reads a positive integer
then outputs "prime" if the number read is a prime number and "not prime" otherwise.
Example of execution:
******************************
********* Prime numbers*******
******************************
Enter a positive integer : 40 --> Not Prime
Enter a positive integer : 37 --> Prime
Problem 7 : Factorial Write an Ada program that reads a postive integer and computes its factorial. Remember that
factorial(0) is 1 and factorial(n)=n*(n-1)*...*1 when n > 0.
Example of execution:
******************************
********* Factorial **********
******************************
Enter a positive integer : 6
Foctorial(6) = 6! : 6*5*4*3*2*1 = 720
Problem 8 : Pattern matching
Write an Ada program that reads three characters (the pattern) then reads a sequence of
characters terminated by # (text); then your output should be the number of occurences of
the pattern in the text.
Example of execution:
**********************************
********* Pattern Matching *******
**********************************
Enter the pattern (three characters) : ada
Enter a text terminated by # : abracadabradadafadawe4op7fnad0dadk#
The number of occurences of ada in the text is : 3