C程序计算一个范围内质数之间的最大差距

C program to calculate largest gap between prime numbers in a range

谁能帮我写这个程序?即使是伪代码也能完成这项工作。 这个程序应该扫描像 34 这样的数字并计算 34 之前素数之间的最大差距,我的意思是 (29-23-1)=5。 非常感谢

int y,x,N,large=3,small=2,b,a;

scanf("%d",&N);

    for(y=3;y<N;++y)
        for(x=2;x<y;++x)
            a=y%x;

    if(a==0) break;

    else if(y>large && y>small) small=large;

    large=y;small=x;b=large-small-1;

    if(b<large-small-1)b=large-small-1;

    printf("%d",b);

can anyone help me write this program ?

好吧,那是 一个明确而具体的问题。 但我不会回答 "Yes.",而是展示你的尝试需要的小重新安排,并在评论。

#include <stdio.h>

main()
{
    int y, x, N, large=2, small, b=0, a;    // don't forget to initialize b
    scanf("%d", &N);
    for (y=3; y<N; ++y)
        for (x=2; x<y; ++x)
        {
            a=y%x;
            if (a==0) break;

            if (x*x < y) continue;      // continue if unsure whether y is prime

            small=large;
            large=y;
            if (b<large-small)
                b=large-small;
            break;                      // we handled this prime y, go to next y
        }
    printf("%d\n", b);
}