我的代码怎么了?为什么我没有得到任何输出?我正在为嵌入式系统练习。
#include <stdio.h>
int checkP (int n)
{
for (int i=2; i<n; i++)
if(n%i==0)
return (0);
return (1);
}
int nextP (int n)
{
do
n++;
while (!checkP(n));
return n;
}
int main (void)
{
int x = 34; //user input
for (int i = 2; i < x - 1; i = nextP(i))
{
if (checkP(x - 1)) {
printf ("\n %d + %d", i, x-1);
}
}
}
[x-1
始终为33
,您想使用x-i
,因此i
和x-i
的总和为x
。
if
应该看起来像这样: