Write a program, making use of a for loop, that prints the numbers 1 to 20 on the console.
Write a program, making use of a for loop, that adds all the whole numbers between 1 and 50. You will need to declare a variable, e.g. total
, which keeps a running total.
Write a program that adds all the even numbers between 1 and 50.
Write a suitable program which outputs all the multiples of 3 up to 50 to the console. Use either a while
or for
loop.
Write a suitable program which outputs all the numbers between 1 and 100 that are 1 more than a multiple of 4; your sequence should start 1, 5, 9, ....
Write a suitable program which works out and outputs all the factors of 100. You may want to consider each number up to 100 and think of a way to determine if it's a factor of 100. Use either a for
loop.
Write a modified form of your programme above that inputs a number, e.g. using prompt(...)
, and finds factors of this number. You may want to consider how to make your programme more efficient.
Write a function that inputs a positive whole number n
, and keeps halving it until you get an odd number, which you should return. You should make use of a while
loop.
Write a function that uses a while
loop to achieve the following:
n
that has been input via the prompt
command.Write a suitable program which outputs all the prime numbers between 1 and 300. You will need a way to determine whether each number you consider is prime.
The Euclidean Algorithm is a well known technique to find the Higher Common Factor of two numbers. For two numbers x
and y
:
y
is 0 then stop and output x
, and vice versa.
x
is divided by y
. For example, when 30 is divided by 4, the quotient is 7 and the remainder is 2.
x
equal to y
and y
equal to this remainder, then go back to Step 1.