Home > Back-end >  The C language
The C language

Time:12-16

Test questions, the great god answers,

CodePudding user response:

Suggest to first try to write yourself ~

CodePudding user response:

Fyi:
 # include & lt; Stdio. H> 

Int func (int n)
{
Int I, r, a, b, c;

R=0;
A=n/100;
B=n % 100/10;
C=n % 10;

If (a==b | | b==c | | c==a)
{
For (I=10; I & lt;=n/2; I++)
{
If (I * I==n)
{
R=1;
break;
}
}
}

Return r;
}

Int main (void)
{
Int n, I;

The scanf (" % d ", & amp; N);

If (n & lt; 101 | | n & gt; 999)
{
Printf (" output wrong \ n ");
return 1;
}

For (I=101; I & lt;=n; I++)
{
If (func (I)==1) printf (" % d \ t ", I);
}

return 0;
}

CodePudding user response:

Two methods for reference:
 # include & lt; Stdio. H> 
#include

Bool isPerSqr (int num);//method 1
Bool isSqr (int n);//method 2

Int main (int arg c, char * argv [])
{
int n;
The scanf (" % d ", & amp; N);
If (n & lt; 101 | | n & gt; 999) return 1;

For (int I=101; i<=n; I++) {
If (isPerSqr (I))
Printf (" [F1] % 4 d ", I);
If (isSqr (I))
Printf (" % [F2] - 4 d \ n ", I);
}
system("pause");
return 0;
}

//method one: do not use the SQRT
Bool isPerSqr (int num)
{
Int n=num;
for(int i=1; N> 0; I +=2) {
N -=I;
}
If (n==0) {
Int a=num % 10;
Int b=num/10% 10;
Int num=c/100;
If (a==b | | a==c | |==b, c) return 1;
}
return 0;
}

//method 2: use SQRT,
Bool isSqr (int n)
{
Int d=(int) (SQRT (n) + 0.5);//round for the
{if (n==d * d)
Int a=n % 10;
Int b=n/10% 10;
Int c=n/100;
If (a==b | | a==c | |==b, c) return 1;
}
return 0;
}
  • Related