首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

习题3.2

2012-12-28 
练习3.2// test2.cpp : Defines the entry point for the console application.//#include stdafx.h#inc

练习3.2

// test2.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <math.h>

bool getR1(int n);

int main(int argc, char* argv[])
{
?printf("Hello World!\n");
?
?printf("result: %d", getR1(6));
?
?return 0;
}

bool getR1(int n)
{
?int sum=1;

?for(int i=2,l=sqrt(n);i<=l;i++)
?{
??if(0== n%i)
??{
???if(n==i*i)
???{
????sum+=i;
???}
???else
???{
????sum+=i;
????sum+=n/i;
???}
??}
?}

?return sum==n;
}

热点排行