#include <stdio.h>
int prime(int num);
int main() {
int upper, lower, tempL, x;
printf("Enter lower limit:");
scanf("%d", &lower);
printf("Enter upper limit:");
scanf("%d", &upper);
for (lower; lower <= upper; lower + 2) {
tempL = lower;
for (lower; lower != 0; lower--) {
if (prime(lower) == 0) { //after decrementing we find a prime
x = tempL - (lower); x = the original lower limit minus the current decremented lower limit
if (prime(x) == 0) { //if x if prime do following
printf("%d = %d + %d\n", tempL, lower, x); //print
break;
}
}
}
}
}
int prime(int number) { //returns 0 if number is prime
int i;
for (i = 2; i < number / 2; i++) {
if (number % i == 0) {
return 1;
}
}
return 0;
}
这就是我到目前为止所拥有的......它所做的只是无休止地打印
999983 = 999983 + 0
我真的被困在这里了。在过去的 8 个小时里,我一直在努力做到这一点。
我正在尝试使用哥德巴赫猜想将数字打印为素数之和。一旦它打印出数字 n 它应该移动到 n+1 直到它达到上限。
现在我有这个
#include <stdio.h>
int prime(int num);
int main() {
int upper, lower, tempL, x;
printf("Enter lower limit:");
scanf("%d", &lower);
printf("Enter upper limit:");
scanf("%d", &upper);
for (lower; lower <= upper; lower + 2) {
tempL = lower;
for (tempL; tempL != 0; tempL--) {
if (prime(tempL == 0) { //after decrementing we find a prime
x = lower - (tempL); x = the original lower limit minus the current decremented lower limit
if (prime(x) == 0) { //if x if prime do following
printf("%d = %d + %d\n", tempL, lower, x); //print
break;
}
}
}
}
}
int prime(int number) { //returns 0 if number is prime
int i;
for (i = 2; i < number / 2; i++) {
if (number % i == 0) {
return 1;
}
}
return 0;
}
但我仍然遇到同样的问题