#include
static int isPrime(int n);
void main()
{
int low,high;
int flag=1;
while(flag==1)
{
printf("输出两个数(一空格分割):");
scanf("%d %d",&low,&high);
/*
//3.利用异或运算来交换数据
// 利用的思想原理是:一个数异或同一个数两次,结果还是那个数,而且不会超出int范围
unsigned int a=60; //0011 1100
unsigned int b=13; //0000 1101
printf("交换之前:a=%d,b=%d\n",a,b); //输出a,b的值
a=a^b; //a=a^b=0011 0001
b=a^b; //b=a^b=0011 1100
a=a^b; //a=a^b=0000 1101
printf("交换之后:a=%d,b=%d\n",a,b); //输出a,b的值
*/
//如果low输入的值大了,交换,保证low的值小于high
if(low>high)
{
low=low^high;
high=low^high;
low=low^high;
}
int i;
static int first=0;
int count=0;
for(i=low;i
for(i=2;i<=n/2;i++)
for(i=2;i<=sqrt(n);i++)
{
if(n%i==0)//如果找到一个其他的因数
{
ISPrime=0;//不是质数
break;
}
}
return ISPrime;
}
测试:
输出两个数(一空格分割):2 234
2, 3, 5, 7, 11, 13, 17, 19, 23, 29,
31, 37, 41, 43, 47, 53, 59, 61, 67, 71,
73, 79, 83, 89, 97, 101, 103, 107, 109, 113,
127, 131, 137, 139, 149, 151, 157, 163, 167, 173,
179, 181, 191, 193, 197, 199, 211, 223, 227, 229,
233。
继续[1/0]?:1
输出两个数(一空格分割):234 56
59, 61, 67, 71, 73, 79, 83, 89, 97, 101,
103, 107, 109, 113, 127, 131, 137, 139, 149, 151,
157, 163, 167, 173, 179, 181, 191, 193, 197, 199,
211, 223, 227, 229, 233。
继续[1/0]?:1
输出两个数(一空格分割):567 334
337, 347, 349, 353, 359, 367, 373, 379, 383, 389,
397, 401, 409, 419, 421, 431, 433, 439, 443, 449,
457, 461, 463, 467, 479, 487, 491, 499, 503, 509,
521, 523, 541, 547, 557, 563。
继续[1/0]?:0
java实现:
package Ctojava;
import java.util.Scanner;
public class printPrimeN_M
{
public static void main(String[] args)
{
int low,high;
Scanner scanner=new Scanner(System.in);
low=scanner.nextInt();
high=scanner.nextInt();
if(low>high)
{
low^=high;high^=low;low^=high;
}
boolean printComma=false;
for(int i=low;i
测试:
1 100
2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97