Help!

Design a program that will allow the user to select from the following :
[1] Math algorithms
[2] Figures
[3] Exit

[1]Math algorithms

a. Euclidean Algorithm
In number theory, the Euclidean algorithm is used for finding the greatest common divisor for two integers a and b (not zero) is based on the following fact:
If r is the remainder when a is divided by b, then gcd (a,b) = gcd (b,r).
See the following Pseudocode:
Euclid(a,b) {
while (b not 0) {
interchange(a,b)
b := b mod a
}
return(a)
}

b. The Ulam Sequence
A mathematician named Ulam proposed generating a sequence of numbers from any positive integer n (n > 0) as follows:
• If n is 1, stop.
• If n is even, the next number is n/2.
• If n is odd, the next number is 3*n + 1.
• Continue with this process until reaching 1.
Ex: an input of 3 gives ->10 ->5 -> 16 ->8 -> 4 -> 2 ->1

c. Fibonacci Series
Fibonacci numbers was invented by Leonardo of Pisa (Fibonacci). He defined fibonacci numbers as a growing population of immortal rabbits. Series of Fibonacci numbers are: 1,1,2,3,5,8,13,21,...
The Fibonacci sequence is 0,1,1,2,3,5,8,13,… where the first two terms are 0 and 1, and each term thereafter is the sum of the two preceding terms; that is Fib[n]=Fib[n-1] + Fib[n-2]. Display the Fibonacci series: example, if n=6, the program should display the value 0,1,1,2,3,5.

d. Fermat Little test
If 2^N modulo N = 2 then N has a high probability to be a prime number.
Ex:
let N=11 (we know that 11 is a prime).
2^11 mod 11 = 2048 mod 11 = 2, then N has a high probability to be a prime number.

Using this information, design a program to list all prime numbers that are less than 100.

Shapes
a. Print a rectangle. Read a height and width and print a rectangle with that height and width. This example output has height 3 and width 7.
*******
*******
*******
b. Print a triangle. Read a number and print a triangle of that size. This example is of size 6.
*
**
***
****
*****
******
c. Print a rectangle outline. Read a height and width and print a rectangle that looks like the one below. This example has a height of 5 and width of 7. You might choose one of two approaches to this problem.
1. Break it down into three problems: a line of stars; lines consisting of a star, blanks, and a star; and again a line of stars.
2. At each position write either a star or blank. Use an if statement to test for first or last row of first or last column, in which case a star is printed, otherwise print a blank.

*******
* *
* *
* *
*******
--------------------------------------------------------------------
Last edited on
Sorry, you need to do your own homework. Code as much as you can, then post specific questions here about specific parts that you are having trouble with.
Topic archived. No new replies allowed.