Help w/ divisors by 4

This is a discussion on Help w/ divisors by 4 within the C Programming forums, part of the General Programming Boards category; For the integers n in the range of 60 to 100, print each on its own row as well as ...

  1. #1
    Registered User BB89's Avatar
    Join Date
    Sep 2009
    Location
    Dallas, Texas
    Posts
    72

    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. #2
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    yeah, % is the modulus operator. So, if n % 4 == 0 then n is divisible by 4

  3. #3
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,047
    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. #4
    Registered User
    Join Date
    Mar 2009
    Posts
    48
    Quote Originally Posted by BB89 View Post
    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. #5
    Registered User BB89's Avatar
    Join Date
    Sep 2009
    Location
    Dallas, Texas
    Posts
    72
    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. #6
    Registered User
    Join Date
    Mar 2009
    Posts
    48
    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. #7
    Registered User
    Join Date
    Jun 2010
    Posts
    1

    Smile help pls dddddd

    Quote Originally Posted by BB89 View Post
    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. #8
    Registered User
    Join Date
    Jun 2009
    Posts
    437
    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
    Last edited by KBriggs; 06-25-2010 at 12:49 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Perfect number and divisors
    By Lissa in forum C Programming
    Replies: 31
    Last Post: 10-24-2008, 01:36 PM
  2. display of divisors
    By Lissa in forum C++ Programming
    Replies: 3
    Last Post: 10-19-2008, 11:20 AM
  3. Finding divisors
    By xbusterx in forum C++ Programming
    Replies: 20
    Last Post: 10-04-2008, 08:08 PM
  4. Help with Computing Divisors
    By MrPink in forum C++ Programming
    Replies: 2
    Last Post: 09-30-2005, 07:35 PM
  5. Find integer 1- 1000 w/ most divisors w/o remainder
    By AlexDeToi in forum C++ Programming
    Replies: 3
    Last Post: 03-24-2002, 07:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21