提交记录 #287
提交时间:2024-11-19 19:49:01
语言:c
状态:CompileError
编译情况:编译错误
code.c: In function ‘isPrime’:
code.c:5:24: warning: ‘return’ with a value, in function returning void [-Wreturn-type]
5 | if (n <= 1) return 0;
| ^
code.c:4:6: note: declared here
4 | void isPrime(int n) {
| ^~~~~~~
code.c:6:24: warning: ‘return’ with a value, in function returning void [-Wreturn-type]
6 | if (n == 2) return 1;
| ^
code.c:4:6: note: declared here
4 | void isPrime(int n) {
| ^~~~~~~
code.c:7:28: warning: ‘return’ with a value, in function returning void [-Wreturn-type]
7 | if (n % 2 == 0) return 0;
| ^
code.c:4:6: note: declared here
4 | void isPrime(int n) {
| ^~~~~~~
code.c:10:32: warning: ‘return’ with a value, in function returning void [-Wreturn-type]
10 | if (n % i == 0) return 0;
| ^
code.c:4:6: note: declared here
4 | void isPrime(int n) {
| ^~~~~~~
code.c:12:12: warning: ‘return’ with a value, in function returning void [-Wreturn-type]
12 | return 1;
| ^
code.c:4:6: note: declared here
4 | void isPrime(int n) {
| ^~~~~~~
code.c: In function ‘isPalindrome’:
code.c:21:20: warning: ‘return’ with a value, in function returning void [-Wreturn-type]
21 | return 0;
| ^
code.c:15:6: note: declared here
15 | void isPalindrome(int n){
| ^~~~~~~~~~~~
code.c:24:12: warning: ‘return’ with a value, in function returning void [-Wreturn-type]
24 | return 1;
| ^
code.c:15:6: note: declared here
15 | void isPalindrome(int n){
| ^~~~~~~~~~~~
code.c: In function ‘main’:
code.c:30:12: error: void value not ignored as it ought to be
30 | if(isPrime(i)){
| ^~~~~~~
code.c:31:16: error: void value not ignored as it ought to be
31 | if(isPalindrome(i)){
| ^~~~~~~~~~~~
固定测试点暂不可用
附加测试点暂不可用
43【学长出题】侯瑞杰:回文素数——用函数
#include<stdio.h>
#include<string.h>
void isPrime(int n) {
if (n <= 1) return 0;
if (n == 2) return 1;
if (n % 2 == 0) return 0;
for (int i = 3; i < n; i += 2) {
if (n % i == 0) return 0;
}
return 1;
}
void isPalindrome(int n){
char str[10000000];
sprintf(str,"%d",n);
int len=strlen(str);
for (int i=0;i<len/2;i++){
if(str[i]!=str[len-i-1]){
return 0;
}
}
return 1;
}
int main(){
int a,b;
scanf("%d%d",&a,&b);
for(int i=a;i<b;i++){
if(isPrime(i)){
if(isPalindrome(i)){
printf("%d\n",i);
return 0;
}
}
}
}