`
lltobe
  • 浏览: 10459 次
社区版块
存档分类
最新评论

练习3.2

    博客分类:
  • C
C 
阅读更多

// 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;
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics