C语言
```c
include include // 判断一个数是否为质数 int isPrime(int num) { if (num <= 1) { return 0; } for (int i = 2; i * i <= num; i++) { if (num % i == 0) { return 0; } } return 1; } // 求指定范围内的所有质数 void findPrimes(int start, int end) { printf("Prime numbers between %d and %d are:\n", start, end); for (int i = start; i <= end; i++) { if (isPrime(i)) { printf("%d ", i); } } printf("\n"); } int main() { int start, end; printf("Enter the start and end numbers: "); scanf("%d %d", &start, &end); findPrimes(start, end); return 0; } ``` Python ```python def is_prime(num): if num < 2: return False for i in range(2, int(num 0.5) + 1): if num % i == 0: return False return True 测试 num = int(input("请输入一个正整数:")) if is_prime(num): print(num, "是质数") else: print(num, "不是质数") ``` Java ```java public class PrimeNumbers { public static void main(String[] args) { int limit = 100; // 输出100以内的质数 System.out.println("质数列表:"); for (int i = 2; i <= limit; i++) { if (isPrime(i)) { System.out.print(i + " "); } } } // 判断一个数是否为质数 public static boolean isPrime(int number) { if (number <= 1) { return false; } for (int i = 2; i <= Math.sqrt(number); i++) { if (number % i == 0) { return false; } } return true; } } ``` JavaScript ```javascript function isPrime(num) { if (num < 2) { return false; } for (let i = 2; i <= Math.sqrt(num); i++) { if (num % i === 0) { return false; } } return true; } // 测试 let num = parseInt(prompt("请输入一个正整数:")); if (isPrime(num)) { console.log(num + " 是质数"); } else { console.log(num + " 不是质数"); } ``` 这些代码示例展示了如何使用不同编程语言判断一个数是否为质数,并输出指定范围内的所有质数。你可以根据需要选择合适的编程语言和代码示例。