C ++程序打印出前四个完美数字 [英] C++ Program that Prints out the first four Perfect Numbers

查看:103
本文介绍了C ++程序打印出前四个完美数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,这是问题所在:

假设m和n为整数,并且m为非零值.回想一下,如果n = mt对于某个整数t,则m称为n的除数;即,当m除以n时,余数为0.此外,如果m <n,则称m为n的适当除数. n和m除以n.如果正整数是其正适当除数的总和,则称其为完美数.例如,28的正固有数为1、2、4、7和14,而1 + 2 + 4 + 7 + 14 =28.因此,28是一个完美的数.编写一个执行以下操作的程序:

一个.输出前四个完美数字
b.输入一个正整数并确定该整数是否为完美数.验证输入.要求用户输入其他输入,直到用户输入0.

您需要实现以下功能:

bool sumOfAllProperDivisors(int m)
如果数字m的正整数除数的总和等于m,则该函数返回true;否则返回false.

您需要使用bool sumOfAllProperDivisors.

So, here is the problem:

Suppose m and n are integers and m is nonozero. Recall that m is called a divisor of n if n = mt for some integer t; that is, when m divides n, the remainder is 0. Moreover, m is called a proper divisor of n if m < n and m divides n. A positive integer is called perfect if it is the sum of its positive proper divisors. For example, the positive proper divisiors of 28 are 1, 2, 4, 7, and 14 and 1 + 2 + 4 + 7 + 14 = 28. Therefore, 28 is a perfect. Write a program that do the following:

a. Output the first four perfect numbers
b. Input a positive integer number and determine whether the integer is perfect. Validate the input. Ask the user to enter another input until the user enters 0.

You are required to implement the following function:

bool sumOfAllProperDivisors (int m)
The function returns true if the sum of positive proper divisors of number m is equal to m;otherwise, it returns false.

You NEED to use bool sumOfAllProperDivisors. How can we make this program work?

推荐答案

为什么不这样做你的家庭作业. (对JSOP的补充) [ ^ ]

这不是一个难题.问题文本中清楚地为您列出了所需的逻辑.我建议您将问题分解为较小的部分,并分别解决每个部分.然后将各个组件绑定到最终解决方案中.
Why do we not do your homework. (Compliments of JSOP)[^]

This is not a difficult problem. The logic required is clearly laid out for you in your question text. I would suggest you break down the question into its smaller components and solve each component separately. Then tie the components together into your final solution.


这篇关于C ++程序打印出前四个完美数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆