完数,顾名思义,就是一个数如果恰好等于它的因子之和。例如6=1+2+3.编写找出1000以内的所有完数

#include <stdio.h>
#include <stdlib.h> int main()
{
int k[];
int i,j,ws,n;
for(j=;j<;j++)
{
ws=j;
n=-;
for(i=;i<j;i++)
{
if(j%i==)
{
n++;
ws-=i;    //判断该数的因子,然后减去
k[n]=i;   //保存该数的所有因子
}
}
if(ws==)  //该数减去它的所有因子,判断是否为0
{
printf("%d is a wanshu.\n",j);
       //打印完数的所有因子
for(i=;i<n;i++)
{
printf("%d,",k[i]);
}
printf("%d\n",k[n]);
}
}
return ;
}

完数c实现的更多相关文章

  1. java程序设计之完数

    题目:一个数如果恰好等于它的因子之和,这个数就称为"完数".例如6=1+2+3.编程 找出1000以内的所有完数. 解题过程也很简单: public class wanshu { ...

  2. 程序设计入门——C语言 第6周编程练习 2 完数(5分)

    2 完数(5分) 题目内容: 一个正整数的因子是所有可以整除它的正整数.而一个数如果恰好等于除它本身外的因子之和,这个数就称为完数.例如6=1+2+3(6的因子是1,2,3). 现在,你要写一个程序, ...

  3. OpenMP求完数

    源代码: #include "stdafx.h" //必须写在首行,因为其前面的include都会被忽略 #include "omp.h" #include & ...

  4. 完数[HDU1406]

    完数 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...

  5. 码农谷 找出N之内的所有完数

    题目描述 一个数如果恰好等于它的因子之和,这个数就称为"完数". 例如,6的因子为1.2.3,而6=1+2+3,因此6是"完数". 编程序找出N之内的所有完数, ...

  6. nyist 597 完数?

    http://acm.nyist.net/JudgeOnline/problem.php?pid=597 完数? 时间限制:1000 ms  |  内存限制:65535 KB 难度:1   描述 一个 ...

  7. 帮初学者改代码——playerc之“练习:求完数问题”(下)

    前文链接:帮初学者改代码——playerc之“练习:求完数问题”(上) 再来看看be_ferfect()应该如何改. be_ferfect()函数的功能是判断number是否为完数,同时把因子对写入d ...

  8. 帮初学者改代码——playerc之“练习:求完数问题”(上)

    原文:“练习:求完数问题” 原代码: // #include <stdio.h> #include <stdlib.h> #include <math.h> #de ...

  9. C++列出完数

    题目内容:自然数中,完数寥若晨星,请在从1到某个整数范围中打印出所有的完数来.所谓“完数”是指一个数恰好等于它的所有不同因子之和.例如,6是完数,因为6=1+2+3.而24不是完数,因为24≠1+2+ ...

  10. openmp 并行求完数

    // GetWanShu.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include "omp.h" #inclu ...

随机推荐

  1. 【HDOJ】4737 A Bit Fun

    水题.不过题目很有趣儿. #include <cstdio> #define MAXN 100005 int a[MAXN]; int main() { int t, n, m; int ...

  2. 构造函数语义学之Default Constructor构建操作

    一.Default Constructor的构建操作 首先大家要走出两个误区: 1).任何class如果没有定义default constructor,就会被合成一个来. 2).便以其合成出来的def ...

  3. common tar command

    Compress tar -cvzf jy2653.2.tgz jy2653.2 Decompress tar -xvf jy2653.1.tgz

  4. Qt入门(16)——组装窗口部件

    这个例子显示了创建几个窗口部件并用信号和槽把它们连接起来,和如何处理重新定义大小事件. #include <qapplication.h> #include <qpushbutton ...

  5. 图论:(Code Forces) Graph and String

    Graph and String time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  6. Eclipse启动jboss局域网无法访问的问题

    在启动jboss的时候加上参数 -b 0.0.0.0(本地用localhost也能访问,用ip也能访问)

  7. Sort List ——LeetCode

    Sort a linked list in O(n log n) time using constant space complexity. 链表排序,要求时间复杂度O(nlgn),我写的归并排序. ...

  8. 数据结构——foodfill 八连块问题

    Description Due to recent rains, water has pooled in various places in Farmer John's field, which is ...

  9. nginx在mac下的安装与基本操作

    1. 安装 brew install nginx(需要安装homebrew) 2. 执行  nginx 直接启动nginx服务 3. nginx -s  reload/stop 4. 配置地址 sud ...

  10. Hat's Fibonacci(大数问题)

    #include <iostream>#include <stdio.h>#include <string.h>using namespace std;int a[ ...