思路:输入n,先求1到这个数的因数,再求和,判断,输出过程和结果
代码:
#include<iostream>
using namespace std;
int main(){
int i,j,m,n,sum = 0;
cin >> n;
for(m = 2;m <= n;m++){
for(i = 1;i <= m / 2;i++)
if(m % i==0)
sum += i;
if(sum == m)
for(j = 1;j <= m / 2;j++){
if(m % j==0)
cout << j << "+";
if(j == m / 2)
cout<<"\b" << "=" << sum << endl;
}
sum=0;
}
return 0;
}
附图: