080.亲密数

简介: 080.亲密数
#include<stdio.h>
void main()
{
    int a,i,b,n,m;
    clrscr();
    printf("================================================================\n");
    printf("     This is a program to find friendly numbers pair.\n");
    printf("   Which means the sum of integer A's all factors (except A)\n");
    printf("    equals to the sum of integer B's all factors (except B).\n");
    printf("     < e.g. sum of integer 6's all factors are:1+2+3=6 >\n");
    printf("================================================================\n");
    printf("\n Please input the scale you want to find n: ");
    scanf("%d",&n);
    printf("\n There are following friendly--numbers pair smaller than %d:\n",n);
    for(a=1;a<n;a++)        /*穷举1000以内的全部整数*/
    {
        for(b=0,i=1;i<=a/2;i++)    /*计算数a的各因子,各因子之和存放于b*/
            if(!(a%i))b+=i;        /*计算b的各因子,各因子之和存于m*/
        for(m=0,i=1;i<=b/2;i++)
            if(!(b%i))m+=i;
        if(m==a&&a<b)
            printf("%4d..%4d    ",a,b);     /*若n=a,则a和b是一对亲密数,输出*/
    }
    puts("\n\n Press any key to quit...");
    getch();
}
相关文章
|
3月前
Armstrong 数
【10月更文挑战第24天】Armstrong 数。
53 7
|
4月前
找出最大的数
【10月更文挑战第18天】找出最大的数。
36 6
|
4月前
比较两个数
【10月更文挑战第13天】比较两个数
29 1
|
9月前
1002 写出这个数
1002 写出这个数
42 0
|
9月前
|
C++
第三大的数(C++)
第三大的数(C++)
67 0
|
人工智能 运维 物联网
数智光伏,走在希望的田野上
数智光伏,走在希望的田野上
|
C++
完美数(C++)
对于一个 正整数,如果它和除了它自身以外的所有 正因子 之和相等,我们称它为 「完美数」。给定一个 整数 n, 如果是完美数,返回 true;否则返回 false。
203 0
|
C++
201612-1 中间数
201612-1 中间数
82 0
201612-1 中间数