User Tools

Site Tools


notes:cprog:spring2024:projects:cnv0

This is an old revision of the document!


CNV0

Background

Determining factor pairs

To determine factor pairs you can make an iterative loop, and check for how many times your input value is evenly divided by a number, ie. for 6 you would check:

6 % 1 = 0, 6 % 2 = 0, 6 % 3 = 0, 6 % 4 = 2, 6 % 5 = 1, 6 % 6 = 0

There are 4 zeros, so 6 has 4 factors.

Determining factor pairs takes a little bit more work than you would imagine, as you cannot simply divide by 2, because of square numbers, who have an odd number of factors.

Instead, you can ignore 1 as a factor, divide the amount of other factors by 2, then add 1 to your amount of factor pairs.

This process may look like:

int i;
for (i=2; i<=input; i++) {
    if ((input % i) == 0) {
    factorpairs++;
    }
}
factorpairs = (factorpairs / 2) + 1

Compiling

Loops

for() loops

while() loops

do-while loops

notes/cprog/spring2024/projects/cnv0.1709598952.txt.gz · Last modified: 2024/03/05 00:35 by cgrant9