0% found this document useful (0 votes)
27 views1 page

Practical 1 - COMP100 Practical 3 PDF

The document provides instructions for 3 programming problems without using functions: 1. A divisibility checker for 3 that sums the digits of a number and checks if the sum is divisible by 3. 2. A program to find all abundant numbers up to the first odd abundant number. An abundant number is one where the sum of its proper factors exceeds the number itself. 3. A program to calculate the sum of all prime numbers between two integers input by the user, where a prime number only has 1 and itself as divisors.

Uploaded by

Darian Chetty
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views1 page

Practical 1 - COMP100 Practical 3 PDF

The document provides instructions for 3 programming problems without using functions: 1. A divisibility checker for 3 that sums the digits of a number and checks if the sum is divisible by 3. 2. A program to find all abundant numbers up to the first odd abundant number. An abundant number is one where the sum of its proper factors exceeds the number itself. 3. A program to calculate the sum of all prime numbers between two integers input by the user, where a prime number only has 1 and itself as divisors.

Uploaded by

Darian Chetty
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

COMP100 2021

Practical 3

**Do not use Functions in your solutions**

1. Divisibility Checker

A common test for divisibility by 3 is to add the individual digits of an integer. If the resulting sum is divisible
by 3 then so is the original number. Program this test in python without the use of strings. Input an integer
from the user, then calculate and output whether the input integer is divisible by 3 or not, using the given
technique.

If for example, the input integer is 234, the resulting sum is: 2+3+4=9, and since 9 is divisible by 3, then we
may output that 234 is divisible by 3.

You must reduce the sum of the individual digits to an integer that is < 20 before testing for divisibility i.e. if
the sum is >= 20, your algorithm must add the digits of the resulting sum.

If for example, the input integer is 999, the resulting sum is: 9+9+9=27, and since it is >=20, we sum
2+7=9 then since 9 is divisible by 3, we may output that 999 is divisible by 3.
This procedure should be repeated until the sum is < 20.

2. Abundant numbers

A positive integer is said to be abundant if the sum of all its proper factors is greater than the integer itself.
The proper factors of an integer are all those integers that divide into the original integer without remainder
but excludes the original integer.

Examples:
 The sum of proper factors of the integer 6 are 1 + 2 + 3 = 6. Therefore 6 is not an
abundant number.
 The sum of proper factors of the integer 12 are 1 + 2 + 3 + 4 + 6 = 16. Therefore 12
is an abundant integer.
 The first few abundant integers are 12,18,20,24, and 30.

Write a python program that will generate all abundant numbers up to and including the first odd abundant
number. No inputs from the user are required.

3. Primes

A prime number is a positive integer that has no other divisors besides 1 and itself. Write a python program
that inputs two positive integers A and B from the user, then calculates and outputs the sum of all the prime
numbers between A and B inclusive.

Page 1 of 1

You might also like