error : expected primary-expression before ' || ' token error : expected ' : ' before ' printf '
#include<math.h>#include<stdio.h>intmain(){inti,j,num;intp,q,flagp,flagq;printf("Plea...
# include <math.h>
# include <stdio.h>
int main () {
int i, j, num;
int p, q, flagp, flagq;
printf("Please input a plus integer: ");
scanf("%d", &num);
// 代码 (num%2)!=0 表示num 不能被2整除
if((num%2)!=0)||(num<=4)
printf("input data error!\n");
else {
p = 1;
// do-while 循环
do {
p = p + 1;
q = num - p;
flagp = 1;
flagp = 1;
// for 循环体
for(i = 2; i <= (int)(floor(sqrt((double)(p)))); i++) {
if((p % i == 0)) {
flagp = 0;
break;
}
}
// while 循环体
j = 2;
while(j <= (int)(floor(sqrt((double)(q))))) {
if((q % j) == 0) {
flagq = 0;
break;
}
j++;
}
} while(flagp * flagq == 0);
printf("%d = %d + %d\n", num, p, q);
}
} 展开
# include <stdio.h>
int main () {
int i, j, num;
int p, q, flagp, flagq;
printf("Please input a plus integer: ");
scanf("%d", &num);
// 代码 (num%2)!=0 表示num 不能被2整除
if((num%2)!=0)||(num<=4)
printf("input data error!\n");
else {
p = 1;
// do-while 循环
do {
p = p + 1;
q = num - p;
flagp = 1;
flagp = 1;
// for 循环体
for(i = 2; i <= (int)(floor(sqrt((double)(p)))); i++) {
if((p % i == 0)) {
flagp = 0;
break;
}
}
// while 循环体
j = 2;
while(j <= (int)(floor(sqrt((double)(q))))) {
if((q % j) == 0) {
flagq = 0;
break;
}
j++;
}
} while(flagp * flagq == 0);
printf("%d = %d + %d\n", num, p, q);
}
} 展开
2个回答
展开全部
没怎么细看楼主的程序,不过楼主的错误显而易见,error : expected primary-expression before ' || ' token error : expected ' : ' before ' printf '已经说明错误出在||附近,printf之前
if((num%2)!=0)||(num<=4)少了右括号。
其实num%2和num<=4也不用再加括号,if的括号就够了。
改过后应为if((num%2)!=0)||(num<=4))
if((num%2)!=0)||(num<=4)少了右括号。
其实num%2和num<=4也不用再加括号,if的括号就够了。
改过后应为if((num%2)!=0)||(num<=4))
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include <stdio.h>
void print_array(int a[],int arraysize);
int max_array(int a[],int arraysize);
int main(void)
{
int j,a[10]=;
for(j=0;j<10;j++)
print_array(a,10); \\这里改为调用数组名就可以了
max_array(a,10); \\这里改为调用数组名
return 0;
}
void print_array(int a[],int arraysize)
{
static int i=0;
printf("%d",a[i]);
i++;
}
int max_array(int a[],int arraysize)
{
int i,t;
for(i=0;i<arraysize;i++)
{
if(a[i]>a[i+1])
{
t=a[i];
a[i]=a[i+1];
a[i+1]=t;
}
}
printf("The max value is %d",a[arraysize-1]);
return 0;
}
请参考
void print_array(int a[],int arraysize);
int max_array(int a[],int arraysize);
int main(void)
{
int j,a[10]=;
for(j=0;j<10;j++)
print_array(a,10); \\这里改为调用数组名就可以了
max_array(a,10); \\这里改为调用数组名
return 0;
}
void print_array(int a[],int arraysize)
{
static int i=0;
printf("%d",a[i]);
i++;
}
int max_array(int a[],int arraysize)
{
int i,t;
for(i=0;i<arraysize;i++)
{
if(a[i]>a[i+1])
{
t=a[i];
a[i]=a[i+1];
a[i+1]=t;
}
}
printf("The max value is %d",a[arraysize-1]);
return 0;
}
请参考
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询