Home > Back-end >  New reports, attention, share c language homework every day
New reports, attention, share c language homework every day

Time:12-11

Novice, please attention, share c language homework every day, thank you for attention, collection!!!!!! If you are also learning c, come on, every day to share high quality questions and answers!

CodePudding user response:

 title description: 

A prime number, which in turn from low remove one, two,... , if the income of each number is prime, still called super primes,

For example: 7331 was a four super prime because 7,73,733,7331 are prime. Try to within 1000 ~ n (1000 & lt; n

CodePudding user response:

 
Bool IsPrime (int n)
{
If (n==1)
return false;

If (n==2
| | n==3
| | n==5
| | n==7)
{
return true;
}

If (n % 2==0)
return false;

If (n % 3==0)
return false;

If (n % 5==0)
return false;

If (n % 7==0)
return false;

Double dn=SQRT (n);
Int CNT=(int) dn.
For (int I=2; i <=CNT; + + I)
{
If I (n %==0)
return false;
}

return true;
}

Void Test (void)
{
Int n=0;
Printf (" please enter n (1000 & lt; n<9999) : ");
Scanf_s (" % d ", & amp; n);
If (n & lt;=1000 | | 9999 & lt;=n)
{
Printf (" input error!" );
return;
}

int count=0;
int sum=0;
Int Max=0;
For (int I=2001; i <=n; + + I)
{
Int test=I;
If (IsPrime (test))
{
The test/=10;
If (IsPrime (test))
{
The test/=10;
If (IsPrime (test))
{
The test/=10;
If (IsPrime (test))
{
+ + count;
The sum +=I;
Max=I;
Printf (" % d \ r \ n ", I);
}
}
}
}
}

Printf (" (1) the number of super prime: % d \ r \ n (2) the sum of all the primes: % d \ r \ n (3) the largest super prime: % d \ r \ n ", count, sum, Max).
}


Please enter n (1000 & lt; n<9999) : 8000
2333
2339
2393
2399
2939
3119
3137
3733
3739
3793
3797
5939
7193
7331
7333
7393
(1) the number of super prime: 16
(2) the sum of all the primes: 68910
(3) the largest super prime number: 7393
Please press any key to continue...

CodePudding user response:

The
reference 1/f, confident boy reply:
 title description: 

A prime number, which in turn from low remove one, two,... , if the income of each number is prime, still called super primes,

For example: 7331 was a four super prime because 7,73,733,7331 are prime. Try to within 1000 ~ n (1000 & lt; n<9999) : (1) the number of super prime (2) the sum of all the primes (3) the largest super primes,


 
Bool IsPrime (int n)
{
If (n==1)
return false;

If (n==2
| | n==3
| | n==5
| | n==7)
{
return true;
}

If (n % 2==0)
return false;

If (n % 3==0)
return false;

If (n % 5==0)
return false;

If (n % 7==0)
return false;

Double dn=SQRT (n);
Int CNT=(int) dn.
For (int I=11; i <=CNT; + + I)//optimization, starting from 11
{
If I (n %==0)
return false;
}

return true;
}

Void Test (void)
{
Int n=0;
Printf (" please enter n (1000 & lt; n<9999) : ");
Scanf_s (" % d ", & amp; n);
If (n & lt;=1000 | | 9999 & lt;=n)
{
Printf (" input error!" );
return;
}

int count=0;
int sum=0;
Int Max=0;
For (int I=2001; i <=n; + + I)
{
Int test=I;
If (IsPrime (test))
{
The test/=10;
If (IsPrime (test))
{
The test/=10;
If (IsPrime (test))
{
The test/=10;
If (IsPrime (test))
{
+ + count;
The sum +=I;
Max=I;
Printf (" % d \ r \ n ", I);
}
}
}
}
}

Printf (" (1) the number of super prime: % d \ r \ n (2) the sum of all the primes: % d \ r \ n (3) the largest super prime: % d \ r \ n ", count, sum, Max).
}

CodePudding user response:

 
Bool IsPrime (int n)
{
If (n==1)
return false;

If (n==2
| | n==3
| | n==5
| | n==7)
{
return true;
}

If (n % 2==0)
return false;

If (n % 3==0)
return false;

If (n % 5==0)
return false;

If (n % 7==0)
return false;

Double dn=SQRT (n);
Int CNT=(int) dn.
For (int I=11; i <=CNT; I +=2)//continue to optimize the I +=2
{
If I (n %==0)
return false;
}

return true;
}