C 练习实例19
C 语言教程
· 2019-02-21 16:41:26
题目:一个数如果恰好等于它的因子之和,这个数就称为"完数"。例如6=1+2+3.编程找出1000以内的所有完数。
程序分析:请参照:C 练习实例14。
实例
// Created by www.codercto.com on 15/11/9.
// Copyright © 2015年 码农教程. All rights reserved.
//
#include<stdio.h>
#define N 1000
int main()
{
int i,j,k,n,sum;
int a[256];
for(i=2;i<=N;i++)
{
sum=a[0]=1;
k=0;
for(j=2;j<=(i/2);j++)
{
if(i%j==0)
{
sum+=j;
a[++k]=j;
}
}
if(i==sum)
{
printf("%d=%d",i,a[0]);
for(n=1;n<=k;n++)
printf("+%d",a[n]);
printf("\n");
}
}
return 0;
}
以上实例输出结果为:
6=1+2+3 28=1+2+4+7+14 496=1+2+4+8+16+31+62+124+248
点击查看所有 C 语言教程 文章: https://codercto.com/courses/l/17.html
The Everything Store
Brad Stone / Little, Brown and Company / 2013-10-22 / USD 28.00
The definitive story of Amazon.com, one of the most successful companies in the world, and of its driven, brilliant founder, Jeff Bezos. Amazon.com started off delivering books through the mail. Bu......一起来看看 《The Everything Store》 这本书的介绍吧!