Files
Learn-Algorithms/9 Algorithms Job Interview/测试代码/9.c
T
2021-03-18 21:24:06 +08:00

54 lines
642 B
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include "stdio.h"
int isSquare(unsigned integer){
if (integer==1 || integer==0)
{
return integer;
}
int divider=2,result=integer/divider;
while(result>divider){
divider++;
result = integer/divider;
}
if (result!=divider)
{
return -1;
}
return result;
}
int main(int argc, char const *argv[])
{
// 243,1849(43),289(17), 64(8)
int a[] = {1849,144,243,289,64,1194877489};
for (int i = 0; i < sizeof(a)/sizeof(int); ++i)
{
int ret = isSquare(a[i]);
if (ret==-1)
{
printf("%d 不是某个数的平方\n",a[i]);
}else{
printf("%d 是 %d 的平方\n", a[i], ret);
}
}
return 0;
}