C语言的问题!哪位大虾帮我详细分析下!好的追加

来源:百度知道 编辑:UC知道 时间:2024/05/13 16:15:55
磁盘上有一个名为testl-l.c的C程序文件,其功能是:计算并输出M以内最大的10个素数之和,M由主函数传给fun 函数。例如:当M的值为100,则函数的值为732。调试程序使之能输出正确的结果。
注意:可以增加和修改程序行,但不得删除程序中的整行。在一处增加的程序行不得超过两行。
源程序如下:
# include <stdio.h>
# include <conio.h>
int fun(int m);
{ int sum,n=0,j,yes;
while((m>=2)&&(n<10)
{ yes=0;
for(j=2;j<=m/2;j++)
if(m%j==0)
{ yes=0;
break;
}
if(yes=1)
{ sum+=m; n++;
m--;
}
}
return ;
}
main()
{ int m;
clrscr();
scanf("%d",m);
printf("%d\n",fun(m));
}
为什么我调试不出来啊 ,他总是有1个错误呢

1.while后面的((m>=2)&&(n<10)这里少了个括号“)”。
2.函数名int fun(int m); 这里错了,后面的“;”是多余的,
3.scanf("%d",m); m前要加"&"
4.if(yes=1) 判断时要用==
.......

调试厚代码如下:

# include <stdio.h>

int fun(int m)
{
int sum=0,n=0,j,yes;
while((m>=2)&&(n<10))
{
yes=0;
for(j=2;j<=m/2;j++)
{
if(m%j==0)
{
yes=0;
break;
}
else yes=1;
}
if(yes==1)
{
sum+=m;
n++;
}
m--;
}
return sum;
}
main()
{
int m;
clrscr();
scanf("%d",&m);
printf("%d\n",fun(m));
}

# include <stdio.h>
# include <conio.h>
int fun(int m);
{ int sum,n=0,j,yes;
while((m>=2)&&(n<10)
{ yes=0;
for(j=2;j<=m/2;j++)
if(m%j==0)
{ yes=0;
break;
}
if(yes=1)
{ sum+=m; n++;