include <stdio.h> #include <conio.h> void main() { int m,i,s; for(m=1;m<=1000;m++) //从1开始到1000循环结束 { s=0;//初始化因子之和s为0 for(i=1;i<m;i++) //寻找在1到m之间,有多少m的因子 if(m%i==0) //如果m能整除i,则i为m的因子 s=s+i;//将因子...
C语言程序如下:include <stdio.h> int main(){ long int i,j,sum;for(i=2;i<100;i++){ sum=0;for(j=2;j<=i/2;j++){ if(i%j==0){ sum=sum+j;} } if(i==sum+1)printf("%d\n",i);} }
这是因为n和sum初始化的位置错了,放到if外面就好了,还有\b只是退格,并不能删除已打印的字符 include<stdio.h>int main(){int i, j, b, n = 0, sum = 0, a[2000];for (i = 1; i <= 1000; i++){for (j = 1; j<i; j++)if (i%j == 0){n++;a[n] = j;sum +=...
include<stdio.h> int main(){ int a,i,b;for(a=2;a<=1000;a++){ b=0;for(i=1;i<a;i++){ if(a%i==0){ b=b+i;} } if(a==b){ printf("完数是%d=",b);for(i=1;i
include <stdio.h>int main(){int i,j;int sum=0, sum1;for (i = 3; i < 2015; i++){sum1 = 0;for (j = 1; j < i; j++)if (i%j == 0)sum1 += j;if (sum1 == i)sum += i;}printf("sum=%d\n", sum);return 0;} ...
//求完数 include<stdio.h> int sum1(int n){int s=0,i;for(i=1;i<=n/2;i++)if(n%i==0)s+=i;return s;} int main(){ int i,j,m,n;scanf("%d%d",&m,&n);for(i=m;i<n;i++)if(sum1(i)==i){printf("%d=1",i);for(j=2;j<=i/2;j++)if(i%j==0)...
== i){ printf("%d = 1", i);for(j=2; j
include<stdio.h>int main(){int i = 0, j = 0, res;for (i = 1; i <= 1000; i++){res = 0;for (j = 1; j < i; j++){if (i % j == 0) res += j;}if (res == i) printf("%d ", i);}printf("\n");return 0;} ...
void main(){ int m,i,s;for(m=1;m<=1000;m++) //从1开始到1000循环结束 { s=0;//初始化因子之和s为0 for(i=1;i<m;i++) //寻找在1到m之间,有多少m的因子 if(m%i==0) //如果m能整除i,则i为m的因子 s=s+i;//将因子累加 if(s==m) //如果因子之和等于这个数 pr...
include<stdio.h> include<math.h> void main(){ int sum,i,j;printf("从1到100内的所有完数是");for(i=1;i<=100;i++){ sum=0;for(int j=1;j