看板 NTUBIME103HW 關於我們 聯絡資訊
有鑑於我揪團功力太差 只好來發解答文 <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)
yangwen5301:.................................................. 11/09 21:57
steve1012:?? 11/09 22:11
joe321pig:看不懂阿大哥BOOL是什麼= =? 11/10 15:00
steve1012:bool就是是非值 true or false 11/10 16:42