problem with the divisor

This is a discussion on problem with the divisor within the C Programming forums, part of the General Programming Boards category; I'm still work with my Prefect Number problem. But still have a little problem, the problem asks show all the ...

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    16

    problem with the divisor

    I'm still work with my Prefect Number problem. But still have a little problem, the problem asks show all the divisor like this"1 + 2 + 3"
    I tried the use "+" in the function, but the problem is i only get "1 + 2 + 3 +"
    Q1: How to get rid of the last "+"?
    Q2: I'm still work on the divisor, hope somebody can show good ideas for the divisor.
    Thank you.
    Here's my code:
    PHP Code:
    #include <stdio.h>
    #include <math.h>

    double ijkbN;
    double prefect();
    double list (double N);

    int main (void)
    {
      
    prefect();
      
    system("pause");
      return 
    0;
    }

    double prefect()
    {
      
    2;
      while(
    <= 1000000000)
      {
        
          
    i=pow(2k-1);
          
    j=pow(2k);
          
    b=i*(j-1);
          
    k++;
          
          if (
    <= 1000000000)
          {
              
    printf(" %.lf = %.lf * %.lf = "bij);
              List(
    N);
          }
      }

      return 
    b;
    }

    //Comment: I'm still work on this divisor function, i really need help on this one//
    double List (double N)
    {
      
    double Div N;

      while (--
    Div 0){

        if ((
    Div) == )
          
    printf ("%d +"Div);
      }


  2. #2
    Registered User Draco's Avatar
    Join Date
    Apr 2002
    Posts
    463
    with regard to printf ("%d +", Div);
    make it be + %d and only print the number the first time.

  3. #3
    Registered User
    Join Date
    Jul 2002
    Posts
    16

    Question

    Sorry, I still don't get it. How to make it work?

  4. #4
    Registered User
    Join Date
    Jul 2002
    Posts
    45
    Prior to attempting to fix your list function (which has lots of problems), perhaps you should look at the output of your prefect function.
    Code:
    if (b <= 1000000000)
          {
              printf(" %.lf = %.lf * %.lf = ", b, i, j);
              List(N);
          }
    What is this supposed to accomplish? I can't make anything out of it when I compile your code.

  5. #5
    Registered User
    Join Date
    Jul 2002
    Posts
    16
    Originally posted by gabulldog
    Prior to attempting to fix your list function (which has lots of problems), perhaps you should look at the output of your prefect function.
    Code:
    if (b <= 1000000000)
          {
              printf(" %.lf = %.lf * %.lf = ", b, i, j);
              List(N);
          }
    What is this supposed to accomplish? I can't make anything out of it when I compile your code.
    The problem is from the divisor"List" function. I'm still debugging.

  6. #6
    Registered User
    Join Date
    Jul 2002
    Posts
    45
    I guess my point is you changed the output of your prefect function from the result of your calculations to an uninteligible output.

    If you trying to get something like:
    "6 = 1 + 2 + 3"

    your code will not produce that no matter what you do to list.

    That's why I recommend you fix prefect prior to working on list.

  7. #7
    Registered User
    Join Date
    Jul 2002
    Posts
    16
    Your idea is really great, but the problem is it's too late, it's due this noon

  8. #8
    Registered User
    Join Date
    Jul 2002
    Posts
    45
    It's never too late. You are almost there.

    I recommend you go back to the original posting and use the printf call you had there. Change it to
    Code:
     printf("\Prefect number: %.0f = ", b);
    or whatever. Then look at your list function and follow Draco's advice.

    20 minutes of work will fix this problem.

  9. #9
    Registered User
    Join Date
    Jul 2002
    Posts
    16
    Originally posted by gabulldog
    It's never too late. You are almost there.

    I recommend you go back to the original posting and use the printf call you had there. Change it to
    Code:
     printf("\Prefect number: %.0f = ", b);
    or whatever. Then look at your list function and follow Draco's advice.

    20 minutes of work will fix this problem.
    Thanks a lot, Do you have any idea about the DIVISOR, the LIST function isn't really come from myself, I don't really understand it.

  10. #10
    Registered User
    Join Date
    Jul 2002
    Posts
    45
    The question I have for you is what is list supposed to accomplish? If you want to get the multiple numbers, you already have a form of them in i, j and k. You just need to figure out how to print them in a readable fashion.

    It won't ever work in its original form because N is already 0, so your first time through will skip the whole while loop.

    Maybe you need to set N to something...

  11. #11
    Registered User
    Join Date
    Jul 2002
    Posts
    16
    Originally posted by gabulldog
    The question I have for you is what is list supposed to accomplish? If you want to get the multiple numbers, you already have a form of them in i, j and k. You just need to figure out how to print them in a readable fashion.

    It won't ever work in its original form because N is already 0, so your first time through will skip the whole while loop.

    Maybe you need to set N to something...
    It asks to get a number of its factors including 1(except the number itself). I want to write a new function for the LIST

  12. #12
    Registered User
    Join Date
    Jul 2002
    Posts
    45
    Sorry I couldn't get back to you in time. Good luck.

  13. #13
    Registered User
    Join Date
    Jul 2002
    Posts
    16
    Thanks, Do you have any idea about the divisor,( not use modulo), That may help also.

  14. #14
    Registered User
    Join Date
    Jul 2002
    Posts
    45
    What you need to do is figure out how to come up with the positive proper divisors. I've looked at the first three perfect numbers and have seen a pattern, which is the sum of the perfect number (b) = 2^0 + 2^1.....2^(k-1) + ((2^k)-1) + 2((2^k-1)...for k-1 times.

    eg:

    6 = 1 + 2+3 = (2^0) + (2^1) +( (2^2)-1)
    28 = 1 + 2 + 4 + 7 + 14 = (2^0) + (2^1) +(2^2) +( (2^3)-1) +
    2((2^3)-1)

    Get the picture? Now all you need to do is to write a loop in your list function to reflect this pattern. And pass the perfect number into your function. Good luck!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 10:22 AM
  2. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  4. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  5. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 05:24 PM

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