Thread: Problem with my output

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User Dogmasur's Avatar
    Join Date
    Jul 2008
    Posts
    72

    Problem with my output

    Okay. So I have started a new program that is meant to query the user to input a number greater than 2. The program then processes that numbers divisors and prints them out on the screen. Eventually, I want the program to also print the sum of those integers to show if the
    number is a perfect number or not.

    The problem I am having right now is with my integers. My program successfully ( and correctly ) prints out my divisors as long as the inputted integer is 30 or less. Anything higher prints 1 and 2. What am I not seeing or what did I do wrong? I'm not worried about the second half of my program yet ( as you can see, I am not there yet in my code). I want to make sure the functionality works before playing with the rest of my input.

    Thanks.

    Code:
     
    
    /*write a program which accepts as input an integer (which must be 2 or greater)*/
    /*and prints out its proper divisors in ascending order, and to print the sum of its */
    /*proper divisors.  The program should also report whether the input number is perfect or not.*/
     
    #include <stdio.h>
     
    int main ( void )
    {
         int n, d = 1;
         
         printf("Enter a number greater than two:\t");
         scanf("&#37;d", &n);
         getchar ();
         
         printf("The proper divisor(s) of %d is:\n", n);
         
         while ( d < n ){
               if ( n % d )
                   d++;
               else
                   printf("%d\t", d);
                   d++;
         }
         
         getchar();
         return 0;
                       
    }
    Last edited by Dogmasur; 08-04-2008 at 07:10 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Hash Table Problem.
    By penance in forum C Programming
    Replies: 9
    Last Post: 07-24-2005, 01:03 PM
  2. output from bank type problem
    By IzaakF in forum C Programming
    Replies: 2
    Last Post: 09-04-2002, 06:42 PM
  3. String Output Problem
    By Yin in forum C++ Programming
    Replies: 3
    Last Post: 03-14-2002, 07:36 AM
  4. Problem with output
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 12-11-2001, 08:32 PM