Perfect number and divisors

This is a discussion on Perfect number and divisors within the C Programming forums, part of the General Programming Boards category; yes but we have a piece of executable file to which we have to stick...

  1. #16
    Registered User
    Join Date
    Oct 2008
    Posts
    28
    yes but we have a piece of executable file to which we have to stick

  2. #17
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    You are not the one who irritated me. It is another thread that was giving me grief.

    Code:
    #include <stdio.h>
    #include <math.h>
    #include <ctype.h>
    
    int main (void) {
      float n, cnt, sum_div;
      char ans;
      do{
        printf("-------------------\n");
        printf("Enter a number:");
        scanf("&#37;f", &n);
    
        cnt = 2.0f;
        sum_div = 0.0f;
    
        printf("Divisors");
        ans = ':'; // Just trust me on this one. Your teacher may think you are a genious.
    
        while((fmod(n,cnt)==0)&&cnt<=n/2.0)
        {
          printf("%c %1.0f", ans, cnt); 
          sum_div+=cnt;
          ans = ',';
    
          if(sum_div==n)
            printf("(Perfect)");
          else if(sum_div>n)
            printf("(Abundant)");
          else
            printf("(Defficient)");
        }
    
        printf("\nContinue? <Y/N>:\n");
        scanf(" %c", &ans);
    
      } while(toupper(ans)=='Y');
      printf("Bye:>_\n");
      return(0);
    }

  3. #18
    Registered User
    Join Date
    Oct 2008
    Posts
    28
    yes but we already have a piece of executable file to which we have to stick

  4. #19
    Registered User
    Join Date
    Oct 2008
    Posts
    28
    this is what i get
    bundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abu
    ndant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abund
    ant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundan
    t), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant)
    , 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant),
    2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(
    Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Ab
    undant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abun
    dant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abunda
    nt), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant
    ), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant),
    2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2
    (Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(A
    bundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abu
    ndant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abund
    ant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundan
    t), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant)
    , 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant),
    2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(
    Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Ab
    undant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abun
    dant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abunda
    nt), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant
    ), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant),
    2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2
    (Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(A
    bundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abu
    ndant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abund
    ant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundan
    t), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant)
    , 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant),
    2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(
    Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Ab
    undant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abun
    dant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abunda
    nt), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant
    ), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant),
    2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2
    (Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(A
    bundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abu
    ndant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abund
    ant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundan
    t), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant)
    , 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant),
    2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(
    Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Ab
    undant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abun
    dant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abunda
    nt), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant
    ), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant),
    2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2
    (Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(A
    bundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abu
    ndant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abund
    ant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundan
    t), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant)
    , 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant),
    2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(
    Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Ab
    undant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abun
    dant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abunda
    nt), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant
    ), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant),
    2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2
    (Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(A
    bundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abu
    ndant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abund
    ant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundan
    t), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant)
    , 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant),
    2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(
    Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Ab
    undant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abun
    dant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abunda
    nt), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant
    ), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant),
    2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2
    (Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(A
    bundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abu
    ndant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abund
    ant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundan
    t), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant)
    , 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant),
    2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(
    Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Ab
    undant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abun
    dant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abunda
    nt), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant
    ), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant),
    2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2
    (Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(A
    bundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abu
    ndant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abund
    ant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundan
    t), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant)
    , 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant),
    2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(
    Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Ab
    undant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abun
    dant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abunda
    nt), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant
    ), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant),
    2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2
    (Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(A
    bundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abu
    ndant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abund
    ant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundan
    t), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant)
    , 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant),
    2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(
    Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Ab
    undant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abun
    dant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abunda
    nt), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant
    ), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant),
    2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2
    (Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(A
    bundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abu
    ndant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abund
    ant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundan
    t), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant)
    , 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant),
    2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(
    Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Ab
    undant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abun
    dant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abunda
    nt), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant
    ), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant),
    2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2
    (Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(A
    bundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abu
    ndant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abund
    ant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundan
    t), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant)
    , 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant),
    2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(
    Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Ab
    undant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abun
    dant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abunda
    nt), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant
    ), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant),
    2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2
    (Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(A
    bundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abu
    ndant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abund
    ant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundan
    t), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant)
    , 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant),
    2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(
    Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Ab
    undant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abun
    dant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abunda
    nt), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant
    ), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant),
    2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2
    (Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(A
    bundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abu
    ndant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abund
    ant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundan
    t), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant)
    , 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant),
    2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(
    Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Ab
    undant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abun
    dant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abunda
    nt), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant
    ), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant),
    2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2
    (Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(A
    bundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abu
    ndant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abund
    ant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundan
    t), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant)
    , 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant),
    2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(
    Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Ab
    undant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abun
    dant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abunda
    nt), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant
    ), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant),
    2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2
    (Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(A
    bundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abu
    ndant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abund
    ant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundan
    t), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant)
    , 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant),
    2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(
    Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Ab
    undant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abun
    dant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abunda
    nt), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant
    ), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant),
    2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2
    (Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(A
    bundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abu
    ndant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abund
    ant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundan
    t), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant)
    , 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant),
    2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(
    Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Ab
    undant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abun
    dant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abunda
    nt), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant
    ), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant),
    2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2
    (Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(A
    bundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abu
    ndant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abund
    ant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundan
    t), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant)
    , 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant),
    2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(
    Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Ab
    undant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abun
    dant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abunda
    nt), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant
    ), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant),
    2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2
    (Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(A
    bundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abu
    ndant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abund
    ant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundan
    t), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant)
    , 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant),
    2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(
    Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Ab
    undant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abun
    dant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abunda
    nt), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant
    ), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant),
    2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2
    (Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(A
    bundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abu
    ndant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abund
    ant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundan
    t), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant)
    , 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant),
    2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(
    Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Ab
    undant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abun
    dant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abunda
    nt), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant
    ), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant),
    2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2
    (Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(A
    bundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abu
    ndant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abund
    ant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundan
    t), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant)
    , 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant),
    2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(
    Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Ab
    undant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abun
    dant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abunda
    nt), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant
    ), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant),
    2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2
    (Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(A
    bundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abu
    ndant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abund
    ant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundan
    t), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant)
    , 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant),
    2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(
    Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Ab
    undant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abun
    dant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abunda
    nt), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant
    ), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant),
    2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2
    (Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(A
    bundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abu
    ndant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abund
    ant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundan
    t), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant)
    , 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant),
    2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(
    Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Ab
    undant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abun
    dant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abunda
    nt), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant
    ), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant),
    2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2
    (Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(A
    bundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abu
    ndant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abund
    ant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundan
    t), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant)
    , 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant),
    2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(
    Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Ab
    undant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abun
    dant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abunda
    nt), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant
    ), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant),
    2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2
    (Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(Abundant), 2(A
    bundant), 2(Abundant)

  5. #20
    Registered User
    Join Date
    Jan 2008
    Posts
    287
    Code:
    ...
        while((fmod(n,cnt)==0)&&cnt<=n/2.0)
        {
          printf("%c %1.0f", ans, cnt);
          break;
          sum_div+=cnt;
          ans = ',';
    ...
    Fixed.

  6. #21
    Registered User
    Join Date
    Oct 2008
    Posts
    28
    yess it works but it shows 2 as the only divisor for any number i enter

  7. #22
    Registered User
    Join Date
    Oct 2008
    Posts
    28
    except for those which cant be divided by 2 actually

  8. #23
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    No printing abundant/perfect/deficient in the inside loop! And since cnt never changes, anywhere, for any reason, why wouldn't it always be 2? (Also, cnt <= n/2.0 is so not what you want.)

  9. #24
    Registered User
    Join Date
    Oct 2008
    Posts
    28
    o my bad cnt has to change. i just incremented it like cnt++

  10. #25
    Registered User
    Join Date
    Jan 2008
    Posts
    287
    I'll let you in on a little secret, this is pretty much the most efficient way to print a list of divisors. Some guy with a swedish sounding name invented the algorithm.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int array_contains(int *A, int len, int key) {
       int i;
       
       for (i = 0; i < len; i++)
          if (A[i] == key) return 1;
       
       return 0;
    }
    
    void print_divisors(int n) {
       static int **super;
       int i, j;
       
       super = malloc((n+1) * sizeof(int*));
       
       super[0] = 0;
       
       for (i = 1; i <= n; i++) {
          super[i] = malloc((n/i) * sizeof(int));
          
          for (j = i; j <= n; j += i)
             super[i][j/i - 1] = j;
       }
       
       printf("Divisors: ");
       for (i = 1; i <= n; i++)
          if (array_contains(super[i], n/i, n))
             printf("%d ", i);
       printf("\n");
       
       for (i = 1; i <= n; i++)
          free(super[i]);
       
       free(super);
    }
    
    int main(void) {
       print_divisors(20);
       return 0;
    }

  11. #26
    Registered User
    Join Date
    Oct 2008
    Posts
    28
    wow.

  12. #27
    Registered User
    Join Date
    Oct 2008
    Posts
    28
    btw thanks to yall who bothered themselves to help me, even though my pblm isnt solved yet^^.

  13. #28
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Oops. Sorry Lissa, I was only modifying your code where applicable, not rewriting it. I didn't even test it or anything since I think I would have used a slightly different approach altogether.

    So lets start off with arpsmack's code, since it works and uses mystical swedish powers:

    Example:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int array_contains(int *A, int len, int key) {
       int i;
       
       for (i = 0; i < len; i++)
          if (A[i] == key) return 1;
       
       return 0;
    }
    
    /*
      * Everyone say "Thank you arpsmack"
      */
    int factor_summation(int n) {
       int sum = 1;
       static int **super;
       int i, j;
       
       super = malloc((n+1) * sizeof(int*));
    
       if(!super)
         return -1;
       
       super[0] = 0;
       
       for (i = 1; i <= n; i++) {
         if(!(super[i] = malloc((n/i) * sizeof(int))))
         {
           for(;i >= 0; --i)
             free(super[i]);
           free(super);
           return -1;
         }
          
          for (j = i; j <= n; j += i)
             super[i][j/i - 1] = j;
       }
       
       for (i = 1; i <= n; i++)
          if (array_contains(super[i], n/i, n))
             sum *= i;
       
       for (i = 1; i <= n; i++)
          free(super[i]);
       
      free(super);
    
      return i;
    }
    
    int main(int argc, char **argv) {
      int i, num, sum;
      const char *options = ", ";
    
      /* Just an optimization */
      --argc;
    
      for(i = 1;i <= argc; ++i)
      {
        num = atoi(argv[i]);
        sum = factor_summation(num);
        if(sum != -1)
          if(sum == num)
            printf("&#37;d is perfect%c ", num, options[!!(i == argc)]);
          else if(2*num < sum)
            printf("%d is abundant%c ", num, options[!!(i == argc)]);
          else
            printf("%d is deficient%c ", num, options[!!(i == argc)]);
    
      return 0;
    }
    Does that work?
    Last edited by master5001; 10-20-2008 at 01:03 PM.

  14. #29
    Registered User
    Join Date
    Oct 2008
    Posts
    28
    um master5001, i think you are using quite an advanced code, we havent reached arrays, yet, dont forget im just a beginner lol. i mean all what w've done so far is selective statements & loops (today).

  15. #30
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Lol.... Ok, sorry Lissa. Then the code I PM'ed you may not be overly helpful either I have to go for a little bit but I can work on this a bit more when I come back.

Page 2 of 3 FirstFirst 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Perfect Numbers C Program
    By SlayerBlade in forum C Programming
    Replies: 2
    Last Post: 08-28-2005, 06:11 PM
  2. Prime number program problem
    By Guti14 in forum C Programming
    Replies: 11
    Last Post: 08-06-2004, 05:25 AM
  3. Replies: 3
    Last Post: 01-14-2003, 10:34 PM
  4. Perfect Number Problem
    By TrazPFloyd in forum C++ Programming
    Replies: 21
    Last Post: 10-20-2002, 12:09 PM
  5. Homework help
    By Jigsaw in forum C++ Programming
    Replies: 2
    Last Post: 03-06-2002, 05:56 PM

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