SoFunction
Updated on 2025-03-07

Example sharing of c# to find prime numbers in range (c# to find prime numbers)

void main()
{
    int low,high,t=0;
printf("Please enter the range where you want to find the prime number (for example, 10~100, enter 10 100)\n");
    scanf("%d %d",&low,&high);
    if(low>high||low<0)
printf("The data you entered is incorrect!");
    else
    {
        for(;low<=high;low++)
        {
            if(low==1||low==0)
                continue;
            int j=0;
            for(int i=2;i<=sqrt(low);i++)
            {
                if(low%i==0)
                {
                    j=1;
                    break;
                }
            }
            if(j==0)
            {
                if(low<10)
                    printf("%d  ",low);
                else
printf("%d ",low);//Alignment of single digits and double digits
                t++;
if(t%4==0)//No four are in a group, line break operation
                    printf("\n");
            }
        }
        if(t==0)
printf("The range you entered has no prime number\n");
        printf("\n");
    }
}