I'm in college and I have to do an assignment on Abundant Numbers (Programmed in C).
Assignment Details are pretty straight forward. Ask for a number determine if it is abundant.
-Use "boolean" function to test a number for abundance.
-use a function to control output and another for input.
-An Abundant Number is a positive integer whose integer factors less than itself sum to a value greater than it.
This is the Code I have so far:
Could someone help me figure out why it declares everything as not an abundant number?Code:#include <stdio.h> #include <math.h> int Input(int N) { printf("Enter the Nth Abundant Number you wish to see: "); scanf("%d", &N); return(N); } int Calc(int N) { int Sum, I, I2; Sum = 0; I2 = sqrt(N); for (I = 1; I >= I2; I++) if ((N % I) = 0) Sum += I + (N / I); return(Sum); } int Check(int N, int Sum, int Abundancy) { if (Sum > N) Abundancy = 1; else Abundancy = 0; return(Abundancy); } int Output(int Number, int Abundancy) { if (Abundancy == 1) printf("%d %s", Number, "is Abundant"); else printf("%d %s", Number, "is not Abundant"); } int main() { /* Variables */ int N, Sum; int Abundancy; /* Start Loop */ while (N != 0) { /* Input */ N = Input(N); for(int I = N; I = (N - 10)or I <= 0; I--) { /* Calculate */ Sum = Calc(N); /* Determine Abundancy */ Abundancy = Check(N, Sum, Abundancy); /* Output */ Output(N, Abundancy); } } }
my test is 12. 1 + 2 + 3+ 4+ 6 = 16, 16 > 12, so it is abundant.



LinkBack URL
About LinkBacks


