gpt4 book ai didi

c - 为什么在打印特定范围的素数后会得到内存位置值?

转载 作者:行者123 更新时间:2023-11-30 16:42:32 25 4
gpt4 key购买 nike

我正在解决this问题:

Peter wants to generate some prime numbers for his cryptosystem. Help him! Your task is to generate all prime numbers between two given numbers!

Input

The input begins with the number t of test cases in a single line (t<=10). In each of the next t lines there are two numbers m and n (1 <= m <= n <= 1000000000, n-m<=100000) separated by a space.

Output

For every test case print all prime numbers p such that m <= p <= n, one number per line, test cases separated by an empty line.

Example

Input:
2
1 10
3 5

Output:
2
3
5
7

3
5

在输出中获得素数后,我获得了内存位置值。你能解释一下我如何在获得最终输出后终止吗?

这是我的代码:

#include <stdio.h>
int main()
{
int t, i, m[10], n[10], j, k, l, isPrime;
// t is test case, m[] and n[] are the lower and upper value of the range of prime numbers
// isPrime is to check the condition True or False.
j = 0;
scanf(" %d \n", &t);

for(i=0; i<t; i++)
{
scanf("%d%d",&m[i],&n[i]);
}

while(j<=i)
{
for(k = m[j]; k<= n[j]; k++)
{ isPrime = 0;
for(l = 2; l<= (k/2); l++){
if(k%l == 0)
{
isPrime = 1;
break;
}
}
if(isPrime==0 && n[j]!= 1)
printf(" %d \n", k);
}
j++;
}
getch();
return 0;
}

最佳答案

您正在使用 getch() ,它将停止程序,直到您在执行完所有程序后按下任意键为止。删除getch(),关闭IDE后编译并运行源文件夹文件中的.exe。

关于c - 为什么在打印特定范围的素数后会得到内存位置值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45783468/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com