# Thread: Help w/ divisors by 4

1. ## Help w/ divisors by 4

For the integers n in the range of 60 to 100, print each on its own row as well as the divisors of n that are evenly divisible by 4.

Code:
#include <stdio.h>

int main (void)
{

int a,
sum = 0;

for( a = 60; a <= 100; a++)
{
sum += a;
printf("%d:\n", a);
}

}
With this I have it printing:
60:
61:
62:
....
....
100:

I am looking to print something like this:
60: 4 12 20 60
...
....
.....
100: 4 20 100

What would I do to print that out? Use a mod?

2. yeah, % is the modulus operator. So, if n % 4 == 0 then n is divisible by 4

3. Note all divisors of a given n that are divisible by 4 will be multiples of 4 also.
Based on this you can insert a nested loop that calculates that for a given n.

4. Originally Posted by BB89
For the integers n in the range of 60 to 100, print each on its own row as well as the divisors of n that are evenly divisible by 4.

...

I am looking to print something like this:
60: 4 12 20 60
...
....
.....
100: 4 20 100

What would I do to print that out? Use a mod?
Yes.
for i from 60 to 100
Determine whether the number(the i in your for loop) is divisible by the divisor ( = 4) .
if (yes)
then print divisor and then
Go on checking the multiples of your divisor whether they are divisible by i .If yes print it.

Sample run.
Code:
60 : 4 12 20 60
64 : 4 8 16 32 64
68 : 4 68
72 : 4 8 12 24 36 72
76 : 4 76
80 : 4 8 16 20 40 80
84 : 4 12 28 84
88 : 4 8 44 88
92 : 4 92
96 : 4 8 12 16 24 32 48 96
100 : 4 20 100

5. I've got this so far.

60:
64:
68:
72:
76:
80:
84:
88:
92:
96:
100:

Code:
#include <stdio.h>

int main (void)
{
int a,
sum = 0;

for( a = 60; a <= 100; a++)
if( a % 4 == 0 )
{
sum += a;
printf("%d:\n", a);
}
}
still having trouble printing the rest of it.

6. Code:
#include <stdio.h>

int main (void)
{
int a,
sum = 0;

for( a = 60; a <= 100; a++)
if( a % 4 == 0 )
{
/* What for  : sum += a;*/
printf("%d:\n", a);
/*Now check for multiples of 4
Is a % 8 == 0  if yes print 8
Is a % 12 == 0  if yes print 12
Is a % 16 == 0 if yes print 16
Use a loop. which runs from 8 to a and checks the above
*/
}
}

7. ## help pls dddddd

Originally Posted by BB89
For the integers n in the range of 60 to 100, print each on its own row as well as the divisors of n that are evenly divisible by 4.

Code:
#include <stdio.h>

int main (void)
{

int a,
sum = 0;(why select sum=0 initially)

for( a = 60; a <= 100; a++)
{
sum += a;-------- meaning of this
printf("%d:\n", a);
}

}
With this I have it printing:
60:
61:
62:
....
....
100:

I am looking to print something like this:
60: 4 12 20 60
...
....
.....
100: 4 20 100

What would I do to print that out? Use a mod?

gjgjgjjxdtutruytutyutyuu
utyutyutyutyu
tyutyutyutyutyutyuy

8. What you are doing is checking if the numbers between 60 and 100 are divisible by 4. That is not what the question is asking. You need to:

find the divisors of each numbers between 60 and 100.
Test if the numbers you found in the previous step are divisible by 4

In pseudocode:

Code:
for a in [60,100] do
for i in [0,a] do
if (i divides a AND 4 divides i) then
print i
end if
end for
end for