4-7 statistic a class of complete squares (20 points)
The subject requires the implementation of a function that determines whether any given integer N
satisfies the condition: it is a total square number, and at least two digits are the same, such as 144, 676, and so on.
function Interface Definition:
int IsTheNumber ( const int N );
These N
are the parameters that the user passed in. If the N
condition is met, the function must return 1, otherwise 0 is returned.
Example of a referee test procedure:
#include <stdio.h>#include <math.h>int IsTheNumber ( const int N );int main(){ int n1, n2, i, cnt; scanf("%d %d", &n1, &n2); cnt = 0; for ( i=n1; i<=n2; i++ ) { if ( IsTheNumber(i) ) cnt++; } printf("cnt = %d\n", cnt); return 0;}/* 你的代码将被嵌在这里 */
Input Sample:
105 500
Sample output:
cnt = 6
int isthenumber (const int N) {int n,m,temp;m=n;n = (int) sqrt (N); if (n*n==m) {int num[10]= {0};<span style= "White-space: Pre "></span>//here the length of NUM should be defined as 10 because the number of digits passed in the integer may be 0~~9 instead of the number of bits passed in. while (m>0) {<span style= "White-space:pre" ></span>//the number on each of the n's, the corresponding array is self-added if there is an array element equal to 2 Description at least 2 digits on the same temp = m%10;for (int i=0; i<=9;i++) {if (temp==i) {num[i]++;if (num[i]==2) {return 1;}}} m/=10;} return 0;} return 0;}
Pta-c-4-7 statistics A class of complete squares (20 points)