Home > Back-end >  Prime Numbers sum and average
Prime Numbers sum and average

Time:10-31

. O 1 ~ 300, all the prime Numbers in the average (function requirement: please use to judge whether a number is prime function, with another function is applied to the prime number 1 ~ 300 to accumulation and averaging function in the output of the main function of the average

CodePudding user response:

 # include & lt; Iostream> 
#include
using namespace std;

Deque Nums;

Void judge_primeNumber (int num_1, int num_2)
{
For (int I=num_1; i <=num_2; I++)
{
If (I==1)
continue;
If (I==2)
{
Nums. Push_back (I);
continue;
}
Int nums=0;
For (int j=2; J & lt; i; J++)
{
Int a_1=I/j;
If (a_1 * j==I)
Nums++;
}
If (nums==0)
Nums. Push_back (I);
}
}

Void average_num ()
{
Int ave=0;
for(int j=0; J & lt; Nums. The size (); J++)
{
Ave +=nums [j];
}
Ave=ave/nums. The size ();
cout }

Int main ()
{
Judge_primeNumber (1, 300);
Average_num ();
}

CodePudding user response:

The
reference # 1/f, wooden pen response:
 # include & lt; Iostream> 
#include
using namespace std;

Deque Nums;

Void judge_primeNumber (int num_1, int num_2)
{
For (int I=num_1; i <=num_2; I++)
{
If (I==1)
continue;
If (I==2)
{
Nums. Push_back (I);
continue;
}
Int nums=0;
For (int j=2; J & lt; i; J++)
{
Int a_1=I/j;
If (a_1 * j==I)
Nums++;
}
If (nums==0)
Nums. Push_back (I);
}
}

Void average_num ()
{
Int ave=0;
for(int j=0; J & lt; Nums. The size (); J++)
{
Ave +=nums [j];
}
Ave=ave/nums. The size ();
cout }

Int main ()
{
Judge_primeNumber (1, 300);
Average_num ();
}

I'm sorry, back to the wrong stickers

CodePudding user response:

Try to run it, I can run successfully on vs
  • Related