Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ partical Tasks A perfect number is an integer that is equal to the sum of its divisors (where 1 is considered a divisor). For

C++ partical

Tasks

A perfect number is an integer that is equal to the sum of its divisors (where 1 is considered a divisor). For example, 6 is perfect because its divisors are 1, 2, and 3, and 1 + 2 + 3 is 6. Similarly, 28 is perfect because it equals 1 + 2 + 4 + 7 + 14. A quite good number is an integer whose badnessthe size of the difference between the sum of its divisors and the number itselfis not greater than a specified value. For example, if the maximum badness is set at 3, there are 12 quite good numbers less than 100: 2, 3, 4, 6, 8, 10, 16, 18, 20, 28, 32, and 64. Your task is to write a C++ program that determines numbers within a designated maximum badness that are less than a limiting value. The limiting value and maximum badness are provided as command line arguments when the program is executed. Command line arguments can be specified within CLion by editing the build configuration.

Q1 : Level 1: Small perfect numbers Begin by writing a program that prints perfect numbers (those with a badness of 0). Separate the output of each number by a single space. Read the limiting value as a command line argument. For example, quitegood 100 should print 6 28. For this level, you can assume that the limiting value will not exceed 10,000.

my code :

#include  #include  using namespace std; int main(int argc, char* argv[]) { const int maxNum = argc > 1 ? atoi(argv[1]) : 100; for (int candidate = 2; candidate < maxNum; candidate++) { int total = 1; for (int factor = 2; factor * factor < candidate; factor++) { if (candidate % factor == 0) total += factor + candidate / factor; } if (total == candidate) { cout << candidate << ' '; } } }

in the pre-set test program show :

Report
Failed test 0: differences in output ..... arguments .................... 100 ..... expected stdout .............. 6 28 ..... observed stdout ..............

how can i pass that ? need to use the similar formal to code. Thanks

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transactions On Large Scale Data And Knowledge Centered Systems Vi Special Issue On Database And Expert Systems Applications Lncs 7600

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Stephen W. Liddle ,Klaus-Dieter Schewe ,Xiaofang Zhou

2012th Edition

3642341780, 978-3642341786

More Books

Students also viewed these Databases questions