[C++ ] 考古題程式解答案 完全數
有鑑於我揪團功力太差
只好來發解答文
<1>判斷完全數文
#include "stdafx.h"
#include "iostream"
using namespace std;
int perfectnum(int);
int _tmain(int argc, _TCHAR* argv[])
{
int k=0;
do
{
for(int j=1;j<=10000;j++)
{
if(perfectnum(j))
cout<<j<<endl;
}
cout<<"please cin k"<<endl;
cin>>k;
}
while(k);
return 0;
}
int perfectnum(int x)
{
int sum=0;
bool perfect=0;
for(int i=1;i<x;i++)
{
if (x%i==0)
sum+=i;
}
if(sum==x)
perfect=1;
return perfect;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 118.161.76.90
※ 編輯: steve1012 來自: 118.161.76.90 (11/09 21:20)
推
11/09 21:57, , 1F
11/09 21:57, 1F
→
11/09 22:11, , 2F
11/09 22:11, 2F
→
11/10 15:00, , 3F
11/10 15:00, 3F
→
11/10 16:42, , 4F
11/10 16:42, 4F