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("%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; }



LinkBack URL
About LinkBacks



