How do you write a 100 to 200 prime number program in C?

Updated on technology 2024-04-13
5 answers
  1. Anonymous users2024-02-07

    There should be a condition:

    main()

    int i,k;

    for (i=1;i<200;i++)

    for(k=2;kif(i%k==0)

    break;

    if (i==k) is the prime number that satisfies this condition, and then outputs.

    printf("%d",i);

  2. Anonymous users2024-02-06

    Prime numbers are only divisible by 1 and itself, and your program is wrong.

  3. Anonymous users2024-02-05

    Well, I agree with s h w's answer! In fact, the ideas of the above two answers are correct, but TG's answer ignores the details. The same is the case with the if statement, but the difference is between if(i==k+1) and if(i==k).

    tg's consideration is correct, and a prime number is a number that is only divisible by 1 and itself. But he didn't consider that if i==k, wouldn't it conflict with the previous statement if(i%k==0)? This will not produce results at all.

    Obviously, S h w has this in mind.

  4. Anonymous users2024-02-04

    Problem solving ideas: first find out all the integers within 100 200, and then let these integers remainder for numbers other than 1 and itself, if there is a divisible number, it is not a prime number, otherwise it is a prime number.

    Start by finding all the integers from 100 to 200, all of which are i

    Use i to find the remainder of a number other than 1 and itself.

    Correct**:

    #include

    int main()

    int conut = 0;

    int i = 0;

    for(i=100; i<=200; i++)int j = 0;

    for(j=2; jif(i%j == 0)break;

    if(j==i)

    conut++;

    printf("%d ", i);

    printf("");

    printf("The number of primes is: %d", conut);

    return 0;

    The judgment condition of the second if statement should be j==i; Instead of i%j.

  5. Anonymous users2024-02-03

    Error reason: After the end of the loop, s is not reset to 1, so the first non-prime number after the second prime is judged is no longer output.

    Here are some examples: <>

    Direct compilation, the program output result is shown in the following figure:

Related questions
4 answers2024-04-13

Gives a function that determines whether a number is prime or not. >>>More

8 answers2024-04-13

int a,b,c;

scanf("%d%d",&a,&b);Enter a, bc=a+b; Add the two numbers to c >>>More

8 answers2024-04-13

Spring The lovely spring girl, with light steps, came to the world, and the scene of vitality came in all directions, and the whole world seemed to have just woken up from a long sleep. >>>More

3 answers2024-04-13

Computer Level 2C language question types and scoring criteria: 1. Multiple choice questions: 40 questions, 1 point for each question. Points are given according to the standard answers. >>>More

3 answers2024-04-13

I like to quietly gaze at the teacher's bright eyes—such beautiful and innocent eyes, which warm people's hearts. When I stepped into the campus, it was your eyes that gave me kindness; When I was disappointed in the exam room, it was your eyes that gave me encouragement; When I am complacent, it is your eyes that warn me. Flashing with light but without a hint of flashiness, full of truth but without a trace of falsehood, slightly serious but not a trace of sharpness. >>>More