Write a program in C about finding the largest prime number within 1000 and print it out

Updated on technology 2024-03-14
5 answers
  1. Anonymous users2024-02-06

    bool f=0;

    for(int i=1000;i>=1;i--) Start with the largest number of 1000 and try to the smaller number.

    for(int j=2;j<=i/2;j++) divides the number i by all the numbers from 2 to i 2, and you can think for yourself why this is possible.

    if(i%j==0){ If i takes the remainder j to 0, i.e. i is divisible by j, if it can, then i is of course not prime, marked and jumped out.

    f=1;break;

    if(f==1){

    f=0;If f==1, i is not the largest prime number, continue. ps: continue can be left unadded.

    continue;

    else{break;

    cout<<"The maximum prime number within 1000 is"<

  2. Anonymous users2024-02-05

    I use C++, which is similar to C.

    Since you're only printing one of the largest prime numbers, it's relatively simple.

    #include

    int main(){

    for (int i=1000; i>=2 ;i--) 2 is the smallest prime number.

    for (int j=2;j<=i/2;j++)if (i%j==0) break;Jump out of the inner loop and go to the outer loop. i-1

    return i;Because the inner loop has already traversed the entire divisor.

    I didn't debug, the general idea is this. */

  3. Anonymous users2024-02-04

    1. First create a new blank C language file, introduce the header file, the header file includes the math library, which will be used later, and establish the main function:

    2. A new function for judging prime numbers is prime, which is based on the fact that the number from 2 to the square root of the arithmetic is a prime number. Then iterate over the numbers from 2 to 100 in the main function, and call isprime to determine that the prime number condition is met and output:

    3. After writing**, finally open the debugging window after compilation, and the screen will print out all prime numbers within 100. That's it for all the prime numbers between 100 in C:

  4. Anonymous users2024-02-03

    Output all prime numbers between 1 and 10000 * include in C

    Determine if a number is prime.

    int is_prime_number(int value){int i = 0;

    if(value <= 1)

    return 0;

    for (i=2; i

    The effect of the program is shown in the following figure (there are too many, one picture can't be finished):

  5. Anonymous users2024-02-02

    Eh: Your if(i==m) is not being used correctly.

    You clearly limited i<=m-1 above, and only when m=2 may i==m be true.

    I'll write it for you.

    #include

    int main()

    if(j==0)

    return 0;}

Related questions
10 answers2024-03-14

Here's a C implementation that assigns an array a[10] to p[n]: >>>More

7 answers2024-03-14

I'll fix it, friend, I don't want to divide it, hehe.

r=0; c=1;It is to assign an initial value to r and c. >>>More

20 answers2024-03-14

Version 2 supports the library edb

Support for library specs >>>More