首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >为什么我得到一个无限循环(因素)?

为什么我得到一个无限循环(因素)?
EN

Stack Overflow用户
提问于 2018-03-05 07:00:43
回答 1查看 72关注 0票数 0

正整数n的适当除数是除n本身以外的n个均匀除法的正整数。例如,16的适当除数是1、2、4和8。

富足数是大于0的整数,使得其适当的除数之和大于整数。例如,12非常丰富,因为1+2+3+4+6 = 16大于12。

亏数是大于0的整数,使得其适当的除数之和小于整数。例如,由于1+2+4 =7(小于8 ),因此8不足。

完美数是大于0的整数,使得其适当的除数之和等于整数。例如,6是完美的,因为1+2+3 =6。

在这里输入图像描述

代码语言:javascript
运行
复制
#include <iostream>
#include <cctype>
#include <iomanip>
#include <cmath>
using namespace std;

    int main()
    {
      int current;
      int possible;
      int sum=0;
      int facts=0;

      cin >> current;

目前为: 17 -5 246

代码语言:javascript
运行
复制
      while(cin){
        cout << current;
        for (possible=1; possible<= current; possible++)
          {
            if(current%possible==0)
              {
              sum= sum + possible;
              facts++;
             if(sum-current > current)
              cout << "is abundant and has" << facts  << "factors" << endl;
            if(sum-current < current)
              cout << "is deficient" << endl;
            if(current < 2)
              cout << "is not abundant, deficient or perfect" << endl;
            if(current == sum-current)
              cout << "is perfect" << endl;

          }
        }
      }

        return 0;
      }

这就是我应该得到的: 17是不足-5不是丰富,不足或完美。246很丰富,有8个因素,而我却得到了一个无限循环。

EN

回答 1

Stack Overflow用户

发布于 2018-03-05 07:19:50

您可以使用int current3代替int current,并检查当前数组的接收端而不是while(cin)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49105024

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档