博客志第一天——判断一个整数N是否是完全平方数?

关注博客园很久,今天是第一次写博客。先附上一个C题目:写一个函数判断一个整数是否为完全平方数,同时是否该数的各位数至少两个相同的数字

 1 #include <stdio.h>
 2 #include <math.h>
 3 
 4 int IsTheNumber ( const int N );
 5 
 6 int main()
 7 {
 8     int n1, n2, i, cnt;
 9                 
10     scanf("%d %d", &n1, &n2);
11     cnt = 0;
12     for ( i=n1; i<=n2; i++ ) {
13         if (IsTheNumber(i))
14             cnt++;
15     }
16     printf("cnt = %d
", cnt);
17 
18     return 0;
19 }
20 int IsTheNumber ( const int N ){
21     int a=N;
22     int i;
23     int count=0;
24     int j=0;
25     int arr[10]={0};
26     int b;
27     if((int)sqrt(N*0.1)*(int)sqrt(N*0.1) == N)
28     { 
29      j=1;
30     }    
31     while(a>0&&count<=10&&j==1)
32     {
33         arr[a%10]++;
34         count++;
35         a=a/10;
36         for(i=0;i<10;i++)
37         {
38             if(arr[i]==2)
39                 return 1;
40         }
41     }
42     return 0;
43 }
原文地址:https://www.cnblogs.com/Wade-James/p/7608254.html