c语言程序设计 帮我看看哪里哪里错了?

大家帮忙看下哪里错了。我用的是VisualC++6.0_c语言吧_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:436,629贴子:
大家帮忙看下哪里错了。我用的是VisualC++6.0收藏
系统显示有一个地方是错的,,但我找不到,, 这个是我个人写的,,题目是输出ABC三个数最大值,,我是新手,,这是第一次写的#include &stdio.h&int main(){
int max(int x,int y);
int a,b,c,d,e;
scanf("%d,%d,%d",&a,&b,&c);
d=max(a,b);
if (d&c) e=d;
printf("%d",e)
int max(int x,int Y){
int x,y,z;
if(x&y) z=x;
return (z);}}
福利不只是穿多穿少,还要有迷人的微笑!
错误信息发上来
闪亮的max函数
在c语言中 大小写不等同
意味着你max函数里面的y没有被赋值 处理很简单 你直接把Y改成y就行
还有printf("%d",e) 这一句没有“;”
还有 函数不要嵌套 把max的描述部分从主函数中拿出来int x,y,z;改成因为你在int max(int x,int y)中已经初始化x,y了
但是我看的是谭教授的第四版的,,里面有一个例题,,只求两个值的最大值,,里面也这样写的,,以前学别的环境好像是不用到int max(int x,int y)这个,,直接把MAX函数写到上面MAIN写在下面的,,
-------------------Configuration: 123 - Win32 Debug--------------------Compiling...123.cf:\资料库\c语言\新建文件夹\123.c(11) : error C2143: syntax error : missing ';' before 'return'f:\资料库\c语言\新建文件夹\123.c(12) : error C2143: syntax error : missing ';' before 'type'f:\资料库\c语言\新建文件夹\123.c(14) : error C2065: 'x' : undeclared identifierf:\资料库\c语言\新建文件夹\123.c(14) : error C2065: 'y' : undeclared identifierf:\资料库\c语言\新建文件夹\123.c(14) : error C2065: 'z' : undeclared identifierf:\资料库\c语言\新建文件夹\123.c(18) : error C2059: syntax error : '}'执行 cl.exe 时出错.123.obj - 1 error(s), 0 warning(s)
我把Y改成小写,,分号也加了还是不行,,#include &stdio.h&int main(){
int a,b,c,d,e;
scanf("%d,%d,%d",&a,&b,&c);
d=max(a,b);
if (d&c) e=d;
printf("%d",e);
int max(int x,int y){
if(x&y) z=x;
return (z);}}大家看看,,这是改完的,,还是有123.obj - 1 error(s), 0 warning(s)一个错误。。我无语了
#include &stdio.h&int main(){ int a,b,c,d,e;scanf("%d,%d,%d",&a,&b,&c);d=max(a,b);if (d&c) e=d;else e=c;printf("%d",e);return 0;}int max(int x,int y){if(x&y) z=x;else z=y;return (z);}拿出来就没有错啊Text1.exe - 0 error(s), 1 warning(s)
1 warning(s)这里变1了
这是警告0 0
#include &stdio.h&int max(int,int);int main(){ int a,b,c,d,e;scanf("%d,%d,%d",&a,&b,&c);d=max(a,b);if (d&c) e=d;else e=c;printf("%d",e);return 0;}int max(int x,int y){if(x&y) z=x;else z=y;return (z);}
老大 我重新翻了下谭浩强的书 人家那里把max函数放在main函数里面?人家好像还有函数声明吧???你仔细看下 我是认真的翻了下所有的例题
--------------------Configuration: 3 - Win32 Debug--------------------Compiling...3.cppCommand line error D2027 : cannot execute 'c1xx'执行 cl.exe 时出错.
把编译器关了再开重新编译
我看了在第四版的第9页,,第1.3例题里,,int max(int x ,int y);在主函数里是声明调用MAX函数,,
我试过了,,重新建一个再把那些复制进去,,还是一样,,就--------------------Configuration: 3 - Win32 Debug--------------------Compiling...3.cppCommand line error D2027 : cannot execute 'c1xx'执行 cl.exe 时出错.3.obj - 1 error(s), 0 warning(s)这个变了。。。
是不是大小写的问题 符号的大小写
恩 你也知道那是调用 ? 要不 你加我qq吧
真的不是在main函数里面 而是用“调用”的方式
函数不能重复包含
谢谢大家的帮忙,,我加你QQ你详细跟我说说吧,,谢谢了
登录百度帐号推荐应用
为兴趣而生,贴吧更懂你。或共有 1629 人关注过本帖
标题:求大神:帮我看看哪里出错了。提示:.exe 文件已停止工作(出现一个问题)
等 级:新手上路
&&已结贴√
&&问题点数:10&&回复次数:2&&&
求大神:帮我看看哪里出错了。提示:.exe 文件已停止工作(出现一个问题)
#include&stdio.h&
#include&stdlib.h&
#include&string.h&
struct student
&&& char name[20];
&&& char college[50];
&&& char degree[20];
&&& struct student *
#define LEN sizeof(struct student)
struct student *creat()//创建链表
&&& struct student *head=NULL;
struct student *insert(struct student *head)//插入结点
&&& struct student *p0,*p1,*p2;
&&& p0=(struct student *)malloc(LEN);
&&& p0-&next=NULL;
&&& printf(&编号:&);
&&& scanf(&%d&,&p0-&num);
&&& printf(&姓名:&);
&&& scanf(&%s&,p0-&name);
&&& printf(&性别(男:1,女:2):&);
&&& scanf(&%d&,&p0-&sex);&&&
&&& printf(&出生日期:&);
&&& scanf(&%d&,&p0-&bir);&&&
&&& printf(&学院:&);
&&& scanf(&%s&,p0-&college);
&&& printf(&学位(学士、硕士、博士in English):&);
&&& scanf(&%s&,p0-&degree);
&&& getchar();
&&& if(head==NULL)head=p0;
&&&&&&&&p1=
&&&&&&&&while((p0-&num&p1-&num)&&(p1-&next!=NULL))
&&&&&&&&&&&&p2=p1;
&&&&&&&&&&&&p1=p1-&
&&&&&&&&if(p0-&num&p1-&num)
&&&&&&&&&&&&if(head==p1)
&&&&&&&&&&&&&&& head=p0;
&&&&&&&&&&&&else p2-&next=p0;
&&&&&&&&&&&&p0-&next=p1;
&&&&&&&&else p1-&next=p0;
&&&&&&&&return (head);
struct student *del(struct student *head,int n)//删除
&&& struct student *p1,*p2=NULL;
&&& while((n!=p1-&num)&&(p1-&next!=NULL))
&&&&&&&&p2=p1;
&&&&&&&&p1=p1-&
&&& if(n==p1-&num)
&&&&&&&&if(p1==head)head=p1-&
&&&&&&&&else p2-&next=p1-&
&&&&&&&&free(p1);
&&&&&&&&printf(&已成功删除!\n&);
&&& else printf(&不存在该学生!\n&);
&&& return (head);
struct student *amend(struct student *head)//修改
&&& struct student *p1,*p2=NULL;
&&& printf(&请输入要修改信息的学生编号:&);
&&& scanf(&%d&,&num);
&&& while((num!=p1-&num)&&(p1-&next!=NULL))
&&&&&&&&p2=p1;
&&&&&&&&p1=p1-&
&&& if(num==p1-&num)
&&&&&&&&printf(&请输入学生信息:\n&);
&&&&&&&&printf(&编号:&);
&&&&&&&&scanf(&%d&,&p1-&num);
&&& else printf(&不存在该学生!\n&);
&&& return (head);
struct student *search(struct student *head)//查找
&&& struct student *p;
&&& int i,j,k;
&&& char ch[20];
&&& printf(&请输入查询方式:(1.编号/2.姓名/3.学院\n&);
&&& scanf(&%d&,&i);
&&& switch(i)
&&& case 1:printf(&请输入学生编号:&);scanf(&%d&,&j);
&&&&&&&&&&&for(k=0;;k++)
&&&&&&&&&&&{
&&&&&&&&&&&&&&&if(p-&num==j)
&&&&&&&&&&&&&&&{
&&&&&&&&&&&&&&&&&& printf(&%s&,p-&name);
&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&if(p-&next==NULL)
&&&&&&&&&&&&&&&p=p-&
&&&&&&&&&&&}
&&& case 2:printf(&请输入学生的姓名:&);getchar();gets(ch);
&&&&&&&&&&&for(k=0;;k++)
&&&&&&&&&&&{
&&&&&&&&&&&&&&&if(strcmp(p-&name,ch)==0)
&&&&&&&&&&&&&&&{
&&&&&&&&&&&&&&&&&& printf(&%s&,p-&name);
&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&if(p-&next==NULL)
&&&&&&&&&&&&&&&p=p-&
&&&&&&&&&&&}
&&& case 3:printf(&请输入学院名称:\n&);getchar();gets(ch);
&&&&&&&&&&&for(k=0;;k++)
&&&&&&&&&&&{
&&&&&&&&&&&&&&&if(strcmp(p-&college,ch)==0)
&&&&&&&&&&&&&&&&&& printf(&%s&,p-&name);
&&&&&&&&&&&&&&&if(p-&next==NULL)
&&&&&&&&&&&&&&&p=p-&
&&&&&&&&&&&}
&&& default:printf(&输入有误!\n&);
void fun6(struct student *head)//统计
&&& struct student *p;
&&& int A=0,B=0,C=0,n=0,i;
&&& for(i=1;;i++)
&&&&&&&&if(p-&bir&=1990)n++;
&&&&&&&&if(p-&next==NULL)
&&&&&&&&p=p-&
&&& printf(&1990年以后出生的学生人数为%d\n&,n);
&&& m=(float)n/i;//90后比例
&&& printf(&90后学生所占比例为:%.2f\n&,m);
&&& for(i=1;;i++)
&&&&&&&&if(strcmp(p-&degree,&boshi&)==0)A++;
&&&&&&&&if(strcmp(p-&degree,&shuoshi&)==0)B++;
&&&&&&&&if(strcmp(p-&degree,&xueshi&)==0)C++;
&&&&&&&&if(p-&next==NULL)
&&&&&&&&p=p-&
&&& printf(&博士人数为:%d\n硕士人数为:%d\n学士人数为:%d\n&,A,B,C);
&&& m=(float)A/i;
&&& printf(&博士学位的学生所占比例为:%.2f\n&,m);
&&& //学位比例
void files(struct student *head)//文件
&&& struct student *p;
&&& int i=0;
&&& FILE *
&&& if((fp=fopen(&data.txt&,&w+&))==NULL)
&&&&&&&&printf(&can't open file!\n&);
&&&&&&&&exit(0);
&&& while(p!=NULL)
&&&&&&&&i++;
&&&&&&&&p=p-&
&&& while(head!=NULL)
&&&&&&&&fwrite(p,LEN,i,fp);
&&&&&&&&head=head-&
&&& printf(&已保存至文件!\n&);
&&& fclose(fp);
void list(struct student *head)//输出
&&& struct student *p;
&&& while(p!=NULL)
&&&&&&&&printf(&%d&,p-&num);
&&&&&&&&p=p-&
struct student *fun1(void)//fun1
&&& struct student *
&&& int n=3;
&&& char ch='y';
&&& head=creat();
&&& while(ch=='Y'||ch=='y')
&&&&&&&&head=insert(head);
&&&&&&&&printf(&继续输入?(y/n):&);
&&&&&&&&ch=getchar();
&&&&&&&&getchar();
struct student *fun3(struct student *head)//fun3
&&& char ch='y';
&&& while(ch=='Y'||ch=='y')
&&&&&&&&printf(&请输入要删除信息的学生编号:&);
&&&&&&&&scanf(&%d&,&n);
&&&&&&&&getchar();
&&&&&&&&head=del(head,n);
&&&&&&&&printf(&继续删除?(y/n):&);
&&&&&&&&ch=getchar();
&&&&&&&&getchar();
void main()
&&& struct student *
&&& while(1)
&&& printf(&\n&);
&&&&&&&&printf(&\t---------------------------------------------------------------\n&);
&&&&&&&&printf(&\t*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *\n&);
&&&&&&&&printf(&\t* **********************&&&高校学生管理系统&&&*****************\n&);
&&&&&&&&printf(&\t*&&&&&&&&&&&&&&&&&&&&&&&学生学号:&&&&&&&&&&&&&&&&&&&&&&&&&&& *\n&);
&&&&&&&&printf(&\t*&&&&&&&&&&&&&&&&&&&&&&&学生班级:&&&&&&&&&&&&&&&&&&&&&&&&&&& *\n&);
&&&&&&&&printf(&\t*&&&&&&&&&&&&&&&&&&&&&&&学生姓名:&&&&&&&&&&&&&&&&&&&&&&&&&&& *\n&);
&&&&&&&&printf(&\t*&&&&&&&&&&&&&&&&&&&&&&&&&&&感谢使用&&&&&&&&&&&&&&&&&&&&&&&&&&*\n&);
&&&&&&&&printf(&\t--------------------------------------------------------------\n\n&);
&&&&&&&&printf(&\t&&&&&&&&&&&&&&&&&&&&&&&1.创建学生信息\n&);
&&&&&&&&printf(&\t&&&&&&&&&&&&&&&&&&&&&&&2.增加学生信息\n&);
&&&&&&&&printf(&\t&&&&&&&&&&&&&&&&&&&&&&&3.删除学生信息\n&);
&&&&&&&&printf(&\t&&&&&&&&&&&&&&&&&&&&&&&4.修改学生信息\n&);
&&&&&&&&printf(&\t&&&&&&&&&&&&&&&&&&&&&&&5.查询学生信息\n&);
&&&&&&&&printf(&\t&&&&&&&&&&&&&&&&&&&&&&&6.统计学生信息\n&);
&&&&&&&&printf(&\t\n&);
&&&&&&&&printf(&\t&&&&&&&&&&&&&&&&&&&&请选择功能按键0-6\n&);
&&&&&&&&scanf(&%d&,&select);
&&&&&&&&getchar();
&&&&&&&&switch(select)
&&&&&&&&case 1:head=fun1();
&&&&&&&&&&&&files(head);
&&&&&&&&case 2:head=insert(head);
&&&&&&&&&&&&files(head);
&&&&&&&&case 3:head=fun3(head);
&&&&&&&&&&&&files(head);
&&&&&&&&case 4:head=amend(head);
&&&&&&&&&&&&files(head);
&&&&&&&&case 5:search(head);
&&&&&&&&case 6:fun6(head);
&&&&&&&&default:printf(&按键错误,请重新选择!\n&);
&&&&&&&&list(head);
[ 本帖最后由 幸运的杨震 于
06:22 编辑 ]
搜索更多相关主题的帖子:
&&&&&&&&&&&&&&&&&&&&&&&&
等 级:贵宾
威 望:304
帖 子:25793
专家分:48814
运行时出错就是程序错,不是“都没错”。
授人以渔,不授人以鱼。
来 自:四川达县
等 级:论坛游民
帖 子:45
专家分:55
这种问题希望你不要发源代码因为源代码太长了没有时间帮你看找错误 发翻译器翻译的错误提示就可以了
版权所有,并保留所有权利。
Powered by , Processed in 0.043343 second(s), 8 queries.
Copyright&, BCCN.NET, All Rights Reserved求高手帮我看看,这个c语言程序哪里有错误??!!_百度知道
求高手帮我看看,这个c语言程序哪里有错误??!!
name,&}, nn)==0) flag=1,以下程序当输入某人姓名时.tel), stud[i].name,&#39,&quot.h&void main(){ struct aa stud[]={&#include &quot,');,输出该人电话号码,'Wangping&quot.h&;
char tel[20];n&struct aa{ char name[10],请填空;;.stdio。#include &
{if(flag==1)printf(&quot:%s\;&n&string:%3; i&};
else printf(&quot.\Liming&
char nn[10];
gets(nn);&zhanghua&.;C&
for(i=0, stud[i]; i++)
if(strcmp(stud[i](1)结构体数组中保存有3个人的姓名和电话号码
提问者采纳
}; i& struct aa stud[]={{&quot,&
char nn[10], nn)==0) flag=1,{&quot,&quot, stud[i];;
{if(flag==1)printf(&3;C
char tel[20], stud[i];;&quot.\n& i++)
if(strcmp(stud[i];):%s\};struct aa{ char name[10];Wangping&void main(){ int flag.&quot.;zhanghua&quot.h&;#include &quot.h&
for(i=0;n&.&
gets(nn)#include &}},{&
else printf(&quot,&Liming&quot.tel):%}
运行了,好像不对呢
能够运行吧,结果就不知道了
能运行,不过结果乱码了
那我好好看看,你也检查一下,可能是哪里没有初始化#include &stdio.h&#include &string.h&struct aa{ char name[10];
char tel[20];};void main(){ int flag = 0; struct aa stud[]={{&Liming&,&&},{&Wangping&,&&},{&zhanghua&,&&}};
char nn[10];
for(i=0; i&3; i++) if(strcmp(stud[i].name, nn)==0) {
if(flag==1)
printf(&name:%s
tel:%s\n&, stud[i].name, stud[i].tel);
printf(&Can not find..\n&);
}} 结果对了Limingname:Liming
tel:Press any key to continue
提问者评价
其他类似问题
为您推荐:
您可能关注的推广
c语言程序的相关知识
其他2条回答
Cn&quot, nn)==0)
flag=1, stud[i];n&},{&&quot.;;
char nn[10], stud[i];#include &
char tel[20],&quot.);Liming&quot修改后,&};3,flag = 0:%&
if(flag==1)
printf(&}}.\ i&};;.h&zhanghua&quot,{&quot.void main(){
struct aa stud[]={{& i++)
if(strcmp(stud[i].h&;
gets(nn);struct aa{ char name[10]:%s\&quot:#include &
break.tel);Wangping&quot
#include &stdio.h&#include &string.h&struct aa{ char name[10];char tel[20];};void main(){ struct aa stud[]={&Liming&,&&,&Wangping&,&&,&zhanghua&,&&};char nn[10];gets(nn);for(i=0; i&3; i++)if(strcmp(stud[i].name, nn)==0)if(i & 3)printf(&name:%s
tel:%s\n&, stud[i].name, stud[i].tel);else printf(&Can not find..\n&);}
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁16:47 提问
C语言代码,新手,帮忙看看哪里有错误
int main()
double a,b,c,disc,x1,x2,realpart,
scanf("%lf,%lf,%lf",&a,&b,&c);
printf("The equation");
if(fabs(a)&=1e-6)
printf("is not a quadratic.\n ");
disc=b*b-4*a*c;
if(fabs(disc)&=1e-6)
printf(" has two equal roots:%8.4f\n",-b/(2*a));
else if(fabs(disc)&1e-6)
x1=(-b+sqrt(disc))/(2*a);
x2=(-b-sqrt(disc))/(2*a);
printf(" has two toots:%8.4fand%8.4f\n",x1,x2);
realpart=-b/(2*a);
imagpart=(b*b-4*a*c)/(2*a);
printf(" has complex roots:\n");
printf("%8.4f+%8.4fi",realpart,imagpart);
printf("%8.4f-%8.4fi",realpart,imagpart);
按赞数排序
你的代码的错误点在于这两句:
x1=(-b+sqrt(disc))/(2*a);
x2=(-b-sqrt(disc))/(2*a);
根据你提供的数据,b^2 - 4ac = 3*3-4*1*6 = -15;
而sqrt()函数的定义是:
double sqrt( double num );
功能: 函数返回参数num的平方根。如果num为负,产生域错误。
有num为负数了,所以sqrt()函数计算出错。
----------------------同志你好,我是CSDN问答机器人小N,奉组织之命为你提供参考答案,编程尚未成功,同志仍需努力!
谢谢各位的耐心解答,问题终结了,修改几处就好了
else if(fabs(disc)&1e-6)
else if(disc&1e-6)
绝对值去掉,防止disc&0还会进入sqrt函数
楼主,你输入的三个值,只有a有给值,b跟c都是0
scanf("%lf,%lf,%lf",&a,&b,&c);中的两个逗号去掉。改成scanf("%lf%lf%lf",&a,&b,&c);
821关注|2702收录
其他相似问题
相关参考资料

我要回帖

 

随机推荐