0

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

Answered # finding divisors of a number using an array

Ancient Dragon 5,243 Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...

0

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

0

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).

This question has already been answered. Start a new discussion instead.

Recommended Articles

the function that I created to find the ...

Hi. so this is actually a continuation from another question of mineHere but i was advised to start a new thread as the original question was already answered.

This is the result of previous question answered :

code for the listbox - datagridview interaction

At the top of the code ...