I´m writing a program to find the divisors of a number, using the modulo function.
my problem is, i´m supposed to use an array to "output" the divisors, and the output should stop when an empty cell is reached. I´m not very confident with arrays and don´t really know how to do this. Any help/ advice is appreciated!!
thanks

2
Contributors
1
2
Views
10 Years
Discussion Span
Last Post by Ancient Dragon

lets say you want an array that can hold up to 10 divisors. Then you would declare it like this: In addition to declaring the array the code below will initialize all elements with 0. `int divisors[10] = {0};` Each of the elements of the array are numbered 0, 1, 2, 3, ... 9. Note that the first element is numbered 0, and not 1. And the last is numbered 9 instead of 10.

How lets say you want to find all the divisors of the number 100. The first divisor will be stored in divisors[0] the next divisor in divisors[1], etc.

A divisor is one in which 100 divided by some number (called the divisor) does not have a remainder. So `100 % 2 == 0` means that 100 is evenly divisible by 2 because it does not have a remainder. Therefore 2 is a divisor and should be inserted into the array.

You will want to create a simple loop that counts from 1 to 100 and check each value of the loop counter to see if it is a divisor of 100 (in the above example).