C language even number decomposition prime number What s wrong Thank you

Updated on technology 2024-05-17
16 answers
  1. Anonymous users2024-02-10

    *It's just that there is something wrong with the cycle conditions, see the changes

    #include

    #define n 3 //

    void f(int a)

    int m,n,i,j=0,k,x[100],flag=0;

    for(k=0;k

    #define n 3 //

    void f(int a)

    int m,n,i,j=0,k,x[100],flag=0;

    for(k=0;kif(a[k]!=0)

    if(a[k]%2!=0)printf("%d is odd number!",a[k]);

    else j=0;

    for(m=2;mi=2; while(m%i!=0)

    i++;if(i==m)

    x[j]=m; j++;

    for(m=0;mfor(n=0;nif(a[k]==x[m]+x[n])

    flag=1;

    break;He's changed, too.

    if (flag) so that flag also comes in handy.

    flag=0;flag to zero.

    break;

    if(a[k]==0)continue;//void main()

    int a[n]=,i;

    for(i=0;iscanf("%d",&a[i]);

    f(a);

  2. Anonymous users2024-02-09

    Without a single line of comment, this habit is not good.

    The program is too messy to read.

  3. Anonymous users2024-02-08

    It's actually very simple, for(k=2; k<=sqrt(m1);k++)if(m1%k==0) break;

    It is used to test whether m1 is prime, if m1 is prime, then no k is divisible by m1, and the end of the loop is that k<=sqrt(m1) is no longer satisfied, that is, k>sqrt(m1). So below.

    if(k>sqrt(m1)) m2=a-m1;

    else continue;

    From the above analysis, it can be seen that sqrt(m1) means that m1 is a prime number, since m1 is a prime number, of course, we have to check whether m2=a-m1 is a prime number; On the contrary, we should see whether the next m1 is prime, that is, it should enter the next loop, so else continue;

  4. Anonymous users2024-02-07

    continue is to end the cycle immediately. Starts the next loop, so it can only be used in while and for blocks.

    With a slight difference, after the continue in the for block ends the loop, execute the third statement in the for parentheses and start the next loop.

    You may be missing braces in your program.

  5. Anonymous users2024-02-06

    Continue means that the remaining statements in the body of the current loop are not executed, and the next cycle is carried out directly.

  6. Anonymous users2024-02-05

    else continue

    It's just that the ** behind it is not done, and the next cycle is carried out directly.

  7. Anonymous users2024-02-04

    There are a lot of problems.,I've modified it according to you.,The program body is wrapped and not changed for you.,So that you can see your own mistakes.,Look at it yourself.。

    #include

    int main()

    int n,i,j,k,l,m,h,flag=0,flag1=0;

    scanf("%d",&n);

    for(i=2;i<=n/2;i++)

    for(k=2;k=n/2;j--)

    for(h=2;h

  8. Anonymous users2024-02-03

    Anyway, can't you encapsulate the judgment of prime numbers as a function?

    Style is important.

    #include

    #include

    int isprime(int n)

    return 1;

    int main()

    return 0;}

  9. Anonymous users2024-02-02

    #include

    #include

    int f(int n) determines whether n is prime, if so, returns 1, otherwise returns 0void main().

    while(num<=2||num%2);

    for (a=2;a<=sqrt(num);a++)if (f(a)&&f(num-a))}

  10. Anonymous users2024-02-01

    Divide this problem into two steps, first get all the primes of <=the even number, then produce two primes, and determine whether their sum satisfies = even. The procedure is as follows:

    #include

    include uses the open function.

    int prime(int m) This function determines whether m is prime, takes a flag bit, and returns 0 if so, void main().

  11. Anonymous users2024-01-31

    #include

    Determine whether n is prime.

    char is_prime(int n)

    int i;

    for(i=2;i

    Running Result:

  12. Anonymous users2024-01-30

    Here's the right procedure, copy, paste, verify, and push!

    #include

    #include

    int fflag(int n);

    void main()}

    int fflag(int i) *determines whether it is prime*

  13. Anonymous users2024-01-29

    I think ha, first calculate the prime number between 3 and 20, (the prime number is odd except 2, and the sum is even, the inevitable prime number cannot have 2, and any other prime number is added to be even, and there is no need to judge later) and then add the two pairs, and the sum is between 10-20 and output, the idea is like this, the procedure is as follows:

    #include

    void main()

    if (j > i/2)

    for(i=0;i=10) Compare and whether the large is equal to 10 and the small is equal to 20}}}

  14. Anonymous users2024-01-28

    #include

    int prime(int now){

    for (int i=2; i>1); j++)if (prime(j) &prime(i-j)){printf("%d+%d Song Circle n"Chi Sakura, i-j, j);

    break;

    return 0;

    Output: Lap wide.

  15. Anonymous users2024-01-27

    #include

    int isprime(int n) void fun(int n) for(i=2; i<=n/2;i++)

    if(isprime(i)&&isprime(n-i))printf("%d = %d + d",n,i,n-i);

    int main()

  16. Anonymous users2024-01-26

    First, use the prime number screening method to find all the prime numbers in a certain range.

    Then, starting from the first prime number until it is greater than or equal to this even number, subtract the previous prime number from this even number to determine whether it is a prime number or not.

Related questions
16 answers2024-05-17

Definition of a for loop.

for(the initial value of the variable; termination of operating conditions; The initial value of the first cycle i is 0, and it runs until i=3 stops i=2, and the condition is still satisfied, and the loop body is still executed, and the step size is 1+1 each time >>>More

9 answers2024-05-17

Hey! This is a very simple function to write, Your Excellency is estimated to have just learned data structures, now learn sorting, lookup, it's easy to give me a reward of two hundred points, I'll help you write it right away. >>>More

8 answers2024-05-17

I thought about it for a long time and didn't come up with it. >>>More

7 answers2024-05-17

It's called the [batch] program, in fact, don't think that the program you mentioned above to deal with garbage is really powerful, it's amazing, when you have learned DOS, that program can be said to be a very simple thing; >>>More

8 answers2024-05-17

system("command");The role is to open the "Command Prompt", and later you can manually enter DOS commands. >>>More