anonymous
  • anonymous
Write a program which given an integer n, classifies it as 'perfect', 'abundant' or 'deficient'. A number is perfect if the sum of its divisors ( excluding the number itself) is equal to the number, e.g. 6. A number is abundant if the sum of its divisors(excluding the number itself) is greater than the number, e.g. 12. A number is deficient if it is neither perfect nor abundant
Computer Science
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
katieb
  • katieb
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
What do you need help with in this problem?
anonymous
  • anonymous
Give at least a pseudocode so that I can understand what to do
KonradZuse
  • KonradZuse
you should try this program out yourself first, before asking people to do it for you.

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

anonymous
  • anonymous
#include 08 using namespace std; 09 10 int main() 11 { 12 int number,counter,total; 13 14 /* Asks for user input*/ 15 cout << "Welcome to the program Factors, this program check to see\n" 16 << "if the number you enter is deficent, perfect or abundant\n" 17 << "this program will read in numbers till you enter -1 and or negitive numbers"; 18 19 while (number > -1) 20 { 21 22 counter = 1; 23 cout << endl; 24 cout << "Please enter a Integer:\n"; 25 cin >> number; 26 cout << endl; 27 28 29 30 if (number % counter == 0) 31 { 32 total= counter + (number % counter); 33 34 cout << total << "+"; 35 counter++; 36 } 37 38 39 40 if (number < total) 41 { 42 cout << endl; 43 cout << number <<" is abundant\n"; 44 45 } 46 else if (number>total) 47 { 48 cout << endl; 49 cout << number << " is deficient\n"; 50 51 cout << endl; 52 } 53 else 54 { 55 cout << endl; 56 cout << number << " is Perfect\n"; 57 58 cout << endl; 59 } 60 61 } 62 63 cout<< endl << endl << endl; 64 system ("pause"); 65 return 0; 66 }
KonradZuse
  • KonradZuse
errrors?
anonymous
  • anonymous
Yeah
KonradZuse
  • KonradZuse
I mean, what are they?
anonymous
  • anonymous
its inaccurate
anonymous
  • anonymous
I think something is wrong with my values?
anonymous
  • anonymous
But i cannot put my finger on it...
KonradZuse
  • KonradZuse
The thing which is annoying is you have to add up EVERY possible combination. So for 12 it's 3 + 4 + 2 + 6....
anonymous
  • anonymous
its like adding prime factors of 12 excluding itself?
anonymous
  • anonymous
so if it is working on a number that isnt perfect It will work through the IF statements to see if it is abundant and another to see if it is deficient
anonymous
  • anonymous
I will post the code properly
anonymous
  • anonymous
#include using namespace std; int main() { int number = 0,counter,total; /* Asks for user input*/ cout << "Welcome to the program Factors, this program check to see\n" << "if the number you enter is deficent, perfect or abundant\n" << "this program will read in numbers till you enter -1 and or negitive numbers"; while (number > -1) { cout << endl; cout << "Please enter a Integer:\n"; cin >> number; if (number < 0) { break; } cout << endl; counter = 1; total = 0; while (counter < number) { if (number % counter == 0) { cout << total << "+" << counter; total += counter; cout << "=" << total << endl; } counter++; } if (number < total){ cout << endl; cout << number <<" is abundant\n"; } else if (number>total) { cout << endl; cout << number << " is deficient\n"; cout << endl; } else { cout << endl; cout << number << " is Perfect\n"; cout << endl; } } cout<< endl << endl << endl; system ("pause"); return 0; }
anonymous
  • anonymous
#include using namespace std; /*------------- -------------*/ int main () { int highNum, abunTotal, defTotal, perfTotal; abunTotal = 0; // sum of divisors more than the number itself defTotal = 0; // sum of divisors less than the number itself perfTotal = 0; // sum of divisors equal to the number itself int sum = 0; cout<< "Please enter a positive integer:"; cin>> highNum; for(int i = 1; i <= highNum; i++ ) { sum = 0; for(int j = 1; j < i; j++ ) { if((i % j) == 0) { sum += j; } } if ( sum == i) //the number is perfect { perfTotal++; cout << "PERFECT NUMBER: " << i << endl; } if ( sum < i) //the number is deficient { defTotal++; } if ( sum > i) //the number is abundant { abunTotal++; } } cout << "The perfTotal is:" << perfTotal << endl; cout << "The defTotal is:" << defTotal << endl; cout << "The abunTotal is:"<< abunTotal << endl; cout << endl; }

Looking for something else?

Not the answer you are looking for? Search for more explanations.