请问这个程序错在哪里?

#include
int main()
{
int max(int x,int y);
int a,b,c;
scanf("%d,%d",&a,&b);
c=max(a,b);
printf("max=%d\n",c);
return 0;
}
int max(int x,int y);
{
int z;
if(x>y)z=x;
else z=y;
return(z);
}
构建时出现一个错误
F:\Test\test1-3.c(12) : error C2449: found '{' at file scope (missing function header?)
F:\Test\test1-3.c(17) : error C2059: syntax error : '}'
执行 cl.exe 时出错.
请问是软件的原因吗?我用的是VC6.0

10个回答

int max(int x,int y);
{
....
}
这里多了一个分号。

第十二行多了一个分号

函数实现的时候不要分号。
而且
int max(int x,int y)
{
int z;
if(x>y)z=x;
else z=y;
return(z);
}
写那么啰嗦干嘛
int max(int x,int y)
{
if (x > y) return x; else return y;
}
不就可以了。

在max函数的定义处多了一个分号

我改了一下,弄了两个版本,请提问者对照自己的程序看一下。
(1)#include

int main()
{
int a,b,c;
scanf("%d,%d",&a,&b);
c=max(a,b);
printf("max=%d\n",c);
return 0;
}

int max(int x,int y);
{
int z;
if(x>y)z=x;
else z=y;
return z;
}
(2)#include
int max(int x,int y);

int main()
{
int a,b,c;
scanf("%d,%d",&a,&b);
c=max(a,b);
printf("max=%d\n",c);
return 0;
}

int max(int x,int y);
{
int z;
if(x>y)z=x;
else z=y;
return z;
}

X_Doy
冰渍小丑橘 #include“stdio.h”,头文件
4 年多之前 回复

#include
第一行改成这样试试

max函数多了个分号,还有如果要把max函数放到main后面,应在main前定义它,或者把整个max函数放到main前

谢谢各位 ,由于在大学时没学好,现在在自学C语言,但是不知道选什么教材好,各位前辈推荐下啊,小弟在此谢了。

lzp_lrp
WorldMobile 建议学习C#吧,目前用的比较多
4 年多之前 回复

int max(int x,int y);
如果函数跟main不是在同一个文件中则在main函数上面这样写进行声明
如果是在同一个文件中,则把max函数直接写在main函数的上方就好了,在main中直接使用

max函数的定义处多了个分号

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
请问这个程序错在哪里??
public class FatherRevenuernprivate double money;rnprivate int year;rnrnFatherRevenue(float m,int y)rnrn money=m;rn year=y;rnrnpublic double Getmoney()rnreturn money=money*0.02;rnrnpublic int Getyear()rn return year;rn rnrnpublic static void main(String args[ ])rnrn FatherRevenue f(11.0,1993)=new FatherRevenue ();rn SonRevenue s(15.0,1995)=new SonRevenue();rn //s.Getyear();rn if(s.Getyear()>1995)rn System.out.println(f.Getmoney());rn elsern System.out.println(s.Getmoney());rnrn rnclass SonRevenue extends FatherRevenuernprivate double money;rnprivate int year;rn谢谢~~rnSonRevenue(double m,int y)rn money=m;rn year=y;rnrnrnpublic double Getmoney()rn money=money*0.03;rn return money;rnrnpublic int Getyear()rnrn return year;rnrn
请问这个程序错在哪里
#includernint main()rnrn char line[81];rn int i,m,n;rn char c;rn gets(line);rn for(i=0;(i=line[i])!='\0';i++)rn rn if(c==' ')rn m++;rn rn n=m+1;rn printf("there are %d words in this line.\n",n);rn return 0;rn
请问这个程序错在哪里!
[code=C/C++]#include "conio.h"rn#include "stdio.h"rnvoid fun(int *a,int *n)rnrn int i,j=0;rn for(i=2;i<1000;i++)rn rn if((i%7==0||i%11==0)&&i%77!=0)rn a[j++]=i;rn rn *n=j;rn rnrnmain()rnrn int aa[1000],n,k;rn FILE *out;rn fun(aa,&n);rn out = fopen("out.txt","w");rn for(k=0;k
请问这个错在哪里
我是照着书上打的,为什么错啊?谁来告诉我啊!!![img=https://forum.csdn.net/PointForum/ui/scripts/csdn/Plugin/001/face/9.gif][/img]rn[img=https://img-bbs.csdn.net/upload/201404/07/1396876556_281922.png][/img]
请问这个错在哪里?
");rnrnrnrnrnrnrn rnrnrnrnrnrnrn老说:常数中有换行符,请问怎么改?rn
这个错在哪里 请问
selectrnk.patient_id,k.visit_id,k.treat_resultrnl.patient_id,l.visit_id,l.dept_discharge_from,l.inp_no,l.doctor_in_charge,l.attending_doctorrnm.patient_id,m.visit_idrnn.dept_code,n.patient_id,n.visit_idrno.dept_codernfromrn(select distinct c.*rn from (select b.patient_id,b.visit_id,b.TREAT_RESULT from diagnosis a join diagnosis b on (a.patient_id=b.patient_id and a.visit_id=b.visit_id)rn where a.TREAT_RESULT='死亡')c)krnleft join pat_visit l on (k.patient_id=l.patient_id and k.visit_d=l.visit_id)rnleft join pat_master_index m on (k.patient_id=m.patient_id and k.visit_id=m.visit_id)rnrnleft join mr_on_line n on (k.patient_id=n.patient_id and k.visit_d=n.visit_id)rn
请问这个错在哪里了
#includernmain()rnrnint stuff[12][10];rnint n,m;rnfor(n=0;n<12;n++)rnrnfor(m=0;m<10;m++)rnstuff[n][m]=0;rnprintf("%d\n",stuff[n][m]);rnrn我想把数组初始化为零并且打印出来,可是运行结果就出来10个0,然后出个-44 -22,请大神看看哪里问题
请问这个错在哪里?
Dim ss(12) As StringrnDim usetime As StringrnDim sql As Stringrn Dim cn As ADODB.Connectionrn Set cn = New ADODB.Connectionrn Set rs = New ADODB.Recordsetrn usetime = "2006-7-15"rn cn.Open "PROVIDER=microsoft.jet.oledb.4.0;data source=" & App.path & "\测量数据.mdb;Persist Security Info=False"rn rn sql = "SELECT * FROM 表8 where ID=534 And 日期= '" & usetime & " '" 'rn rs.Open sql, cnrn rn For i = 1 To 10rn ss(i) = rs.Fields(i - 1)rn Next irn rn cn.Closernrn运行时,运行到 语句rs.Open sql, cn时,提示错误说:语法错误(操作符丢失)在查询表达式'ID=534 And 日期= '2006-7-15''中。rn我是初学者,谁可以帮我解答一下?
这个程序错在哪里?
#includerntemplaternclass HasFriendrnrn private:rn T item;rn static int ct;rn public:rn HasFriend(const T & i):item(i)ct++;rn ~HasFriend()ct--;rn friend void counts();rn friend void reports(HasFriend&);rn;rnrntemplaternint HasFriend::ct=0;rnrnrnvoid counts()rnrn cout<<"int count:"<::ct<::ct<& hf)rnrn cout<<"HasFrind:"<& hf)rnrn cout<<"HasFriend:"<hfil(10);rn HasFriendhfi2(20);rn HasFriendhfd(10.5);rn reports(hfi2);rn reprots(hfd);rn counts();rnrn return 0;rnrn错误信息:rn.cpp(34) : error C2248: 'item' : cannot access private member declared in class 'HasFriend'rn.cpp(6) : see declaration of 'item'rnError executing cl.exe.rn请问怎样修改?
这个程序错在哪里
#includernint main()rnrn char line[81];rn int i,m,n;rn char c;rn gets(line);rn for(i=0;(i=line[i])!='\0';i++)rn rn if(c==' ')rn m++;rn rn n=m+1;rn printf("there are %d words in this line.\n",n);rn return 0;rn
这个程序错在哪里了?
import java.awt.*;rnimport java.awt.event.*;rnimport java.util.*;rnimport javax.swing.*;rnimport javax.swing.Timer;rnrnpublic class Testrnrn public static void main(String[] args)rn rn ActionListener listener = new A();rn // A listener = new A(); //为什么不是这样?rn Timer t = new Timer(10000, listener);rn t.start();rn rn JOptionPane.showMessageDialog(null, "Quit program?");rn System.exit(0);rn rnrnrnclass A implements ActionListenerrnrn public void actionPerfored(ActionEvent event)rn rn Date now = new Date();rn System.out.println("At the tone, the time is " + now);rn Toolkit.getDefaultToolkit().beep(); rn rnrnrn错误提示是rnrn[img=https://img-bbs.csdn.net/upload/201311/27/1385521553_906210.png][/img]rn
这个程序错哪里了
程序编译运行无错,结果却不对。rn#include rn#include rn#define num 100rntypedef char DataType;rntypedef struct node rnDataType data;rnstruct node *lchild,*rchild;rnBinTNode;rntypedef BinTNode * BinTree;rnint found;rnBinTNode *p;rnBinTree CreateBinTree(BinTree bt)rnrnBinTNode * Q[num];rnBinTNode * s;rnint front ,rear;rnchar ch;rnch=getchar();bt=NULL;rnfront=1;rear=0;rnwhile(ch!='#')rns=NULL;rnif(ch!='@')rns=(BinTNode *)malloc(sizeof(BinTNode));rns->data=ch;rns->lchild=s->rchild=NULL;rnrnrear++;rnQ[rear]=s;rnif(rear==1)rnbt=s;rnelsernrnif(s!=NULL && Q[front]!=NULL)rnif(rear % 2==0)rnQ[front]->lchild=s;rnelsernQ[front]->rchild=s;rnif(rear % 2 !=0)rnfront ++;rnrnch=getchar();rnrnreturn bt;rnrnvoid Preorder(BinTree bt)rnrnBinTNode * stack[num];rnint top=0;rnBinTNode * s;rnstack[top]=bt;rnwhile(top>=0)rnrns=stack[top];rntop--;rnif(s!=NULL)rn printf("%c",s->data);rntop++;rnstack[top]=s->rchild;rntop++;rnstack[top]=s->lchild;rnrnrnrnvoid Inorder(BinTree bt)rnrnBinTNode * stack[num];rnint top=0;rnstack[top]=bt;rndornrnwhile(stack[top]!=NULL)rnrntop=top+1;rnstack[top]=stack[top-1]->lchild;rnrntop=top-1;rnif(top>=0)rnrnprintf("%c",stack[top]->data);rnstack[top]=stack[top]->rchild;rnrnwhile(top>=0);rnrnvoid Postorder(BinTree bt)rnrnBinTNode * stack[num];rnint tag[num];rnint top;rnBinTNode * s;rntop=0;rns=bt;rndornrnwhile(s!=NULL)rnrntop++;rnstack[top]=s;rntag[top]=0;rns=s->lchild;rnrnif(top>0)rnrns=stack[top];rnif(top>0)rnrnprintf("%c",stack[top]->data);rntop--;rns=stack[top];rnrnif(top>0)rnrnif(tag[top]!=1)rns=s->rchild;rntag[top]=1;rnrnelse s=NULL;rnrnrnwhile(top!=0);rnrnvoid main()rnrnBinTree bt;rnint xz=1;rnchar ch1;rnwhile(xz)rnprintf(" 二叉树的遍历 \n");rnprintf("================================\n");rnprintf(" 1.建立二叉树的存储结构 \n");rnprintf(" 2.求二叉树的前序遍历 \n");rnprintf(" 3.求二叉树的中序遍历 \n");rnprintf(" 4.求二叉树的后序遍历 \n");rnprintf(" 0.退 出 系 统 \n");rnprintf("================================\n");rnprintf(" 请 选 择 :0—4 ");rnscanf("%d",&xz);rnswitch(xz)rncase 1: printf("输入二叉树的按层结点值,用@表示空节点,#表示结束(按完全二叉树): \n");rnbt=CreateBinTree(bt);rnprintf("二叉树的链式存储结构建立完成! \n");rnbreak;rncase 2: printf("该二叉树的前序遍历序列为: ");rnPreorder(bt);rnprintf("\n");rnbreak;rncase 3: printf("该二叉树的中序遍历序列是 ");rnInorder(bt);rnprintf("\n");rnbreak;rncase 4: printf("该二叉树的后序遍历序列是 ");rnPostorder(bt);rnprintf("\n");rnbreak;rncase 0: return;rnrnrn
这个程序错在哪里??
clearrnset talk offrnuse shebei.dbfrnaccept "输入待查询的编号:" to hhrnlocate for BIANHAO=hhrnLIST FIELDS BIANHAO,QIYONGRIQI,JIAGErnusernset talk onrn
这个程序错哪里?
#include rnrnvoid initialize(long *head)rnrn long *p=head;rn int i;rn for(i=0;i<1000;i++)rn rn *p=i;rn p++;rn cout<<*p<
这个程序错在哪里!
#includern#includernusing namespace std;rn#includernvoid main()rnrn void taxis (b[][10]); rn int n;rn char a[10][10];rn char* p=a;rn cin>>p[0];rn n=strlen(p); //n=strlen(p[0])rn for (int i=1;i<10;i++)rn rn cin>>p[i]; // p++rn if (strlen(p[i])!=n) cin>>p[i];rn rn taxis(a);rn for (i=0;i<10;i++)rn cout<
这个程序错在哪里?
import java.awt.*;rnimport java.awt.event.*;rnrnpublic class ch extends Frame implements ItemListenerrnrnpublic static void main(String[] args) rnrn new ch();rnrn rn Choice size;rnPanel p1,p2,p3,p4;rn Label e1,e2,e3,e4,e5,msg;rn TextField text1,text2,text3,text4,text5;rnrn rn /* p1=new Panel();p2=new Panel();p3=new Panel();rn p1.add(e1);*/rnrnch()rnrn public void init()rn rn size = new Choice();rn e1=new Label("设备维修编号");rn e2=new Label("设备编号");rn rn text2=new TextField(20);rn p1=new Panel();rn p1.add(e1);rn size.add("10");rn size.add("14");rn size.add("18");rn p1.add(size);rn p1.add(e2);rn p1.add(text2);rn setLayout(new FlowLayout());rn add(p1);rnrn rn size.addItemListener(this);rn rn public void itemStateChanged(ItemEvent e)rn rn rn String s;rn rnrn if(e.getItemSelectable() instanceof Choice)rn rn Choice ctemp = (Choice)(e.getItemSelectable());rn s = ctemp.getSelectedItem();rn System.out.println(s);rn
这个程序错在哪里??
rnrnrn rn 调查问卷rnrnrn rn rn rn rn调查问卷rnrnrnrnrn rn 您认为您的经济实力,一个月花费多少用于上网可以接受?rnrn rn rn rn rn rn rn rnrn每月在1000元以上 rnrn每月在500-1000元之间 rnrn每月在200-500元之间 rnrn每月在100-200元之间 rnrn以上还是太贵了rnrnrn rn rnrnrnrnrnrnrn rnrnrnrnrn
这个程序错在了哪里?
一个简单的窗口程序,编译时都正确,可是连接就出了错误,如下两个,而且不指明我错在了那里。rn(1)LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _mainrn(2)Debug/test.exe : fatal error LNK1120: 1 unresolved externalsrn源文件如下:rnrn#includernLRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);rnint APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,rn LPSTR lpCmdLine,int nCmdShow)rnrn WNDCLASS wndclass;rn HWND hwnd;rn MSG msg;rn //定义窗口类rn wndclass.style=CS_HREDRAW|CS_VREDRAW;rn wndclass.lpfnWndProc=WndProc;rn wndclass.cbClsExtra=0;rn wndclass.cbWndExtra=0;rn wndclass.hInstance=hInstance;rn wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);rn wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);rn wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);rn wndclass.lpszMenuName=NULL;rn wndclass.lpszClassName="Ctest";rn if(!RegisterClass(&wndclass)) return FALSE;rn //定义窗口rn hwnd=CreateWindow("Ctest",rn "test",rn WS_OVERLAPPEDWINDOW,rn CW_USEDEFAULT,rn CW_USEDEFAULT,rn CW_USEDEFAULT,rn CW_USEDEFAULT,rn NULL,rn NULL,rn hInstance,rn NULL);rn ShowWindow(hwnd,nCmdShow);rn UpdateWindow(hwnd);rn //消息循环rn while (GetMessage(&msg,NULL,0,0))rn rn TranslateMessage(&msg);rn DispatchMessage(&msg);rn rn return msg.wParam;rnrnrnLRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam, LPARAM lParam)rnrn switch(message)rn rn case WM_PAINT:rn HDC hdc;rn PAINTSTRUCT ps;rn hdc=BeginPaint(hwnd,&ps);rn TextOut(hdc,0,0,"This is a Windows example.",26);rn EndPaint(hwnd,&ps);rn return 0;rn case WM_DESTROY:rn PostQuitMessage(0);rn return 0;rn rn return DefWindowProc(hwnd,message,wParam,lParam);rn
请问这个程序错在哪里? c语言
一个字符数组,奇数下标的变成大写字母,可是运行后确没有效果,哪位给看看 感激~~rnrnvoid ff(char ss[])rnint i,n;rnn=strlen(ss);rnfor(i=0;i='a'&&ss[i]<='z')rnss[i]=ss[i]-32;rnrnrnint main(void)rnrnchar ss[100];rnscanf("%s",ss);rnff(ss[100]);rn printf("%s",ss);rngetch();rnrn
请问这个小程序错在哪里?
#includern#includernint main()rnchar s1[]="ABCDEFG";rn char s2[]="xyz";rn cout<<"Before strcpy (s1 s2);\n";rn cout<<"\ts1=["<
请问这个读取文件数据的程序错在哪里?
#includern#includern#includern#includernstruct meeting_time rn rn int num; rn char month[3];rn int year; rn int h; rn int m; rn float s; rn char station[3];rn ;rnclass singlestar_singlescenariorn rn public:rn int i;rn char textnanme[20];rn int N;rn int num; rn char month[3];rn int year; rn int h; rn int m; rn float s; rn char station[3];rnrn void reading() ;rn meeting_time *p;rnrn; rn //读取每个文件的数据rn void singlestar_singlescenario::reading()rn rnrn //用一个结构体储存信息. rn p=new meeting_time[N];rn FILE *fp; rn fp=fopen("textname[20].txt","r"); rn fscanf(fp,"%s\n",&p[0].station);rn cout<
请问各位高手这个程序错在哪里?
#includernclass TDaternrnpublic:rn void SetDate(int y,int m,int d);rn int IsLeapYear();rn void Print();rnprivate:rn int year,month,day;rn;rnvoid TDate::SetDate(int y,int m,int d)rnrn year=y;rn month=m;rn day=d;rnrnint TDate::IsLeapYear()rnrn return(year%4==0 && year%100!=0) || (year%400==0);rnrnvoid TDate::Print()rnrn cout<
请问这个程序错在哪里啊?
#include rn#include rn#include rnusing namespace std;rnvoid main()rnrn string filename;rn cout<<"please input the filename"<>filename;rn cout<<"now type the content of the file"<
请问大家这个程序错在哪里?
public class Student0rnrn String name;rn int age;rn boolean Equals(Object obj)rn Student st=null;rn if(obj instanceof Student)rn st = (Student)obj;rn elsern return false;rn if(st.name==this.name && st.age==this.age)rn return true;rn elsern return false;rn rn public static void main(String[] args) rn Student p=new Student();rn Student q=new Student();rn p.name="xyz";rn p.age=13;rn q.name="xyz";rn q.age=13; rn if(p.Equals(q))rn System.out.println("p 与 q 相等");rn elsern System.out.println("p 与 q 不等");rn rnrn编译错误:没有为类型 Student 定义方法 Equals(Student)
请问这个程序错在哪里?求解!
#include "stdio.h"rn#define n 10rnvoid main()rnint k,i,mid,left,right;rn int table[n]=0,2,4,6,8,10,12,14,16,18;rn int find=0;rn printf("请输入要查找的数:");rn scanf("%d",&k);rn while(!find&&left
请问这个程序错在哪里?谢谢
#include rnclass Personrnrn private:rn char Name;rn int Age;rn int Height;rn int Weight;rn public:rn Person(char name, int age, int height, int weight);rn printPerson();rnrnrnPerson::Person(char name,int age,int height,int weight)rnrn Name = name;rn Age = age;rn Height = height;rn Weight = weight;rnrnrnPerson::printPerson()rnrn cout << Name << Age << Height << Weight << endl;rn return 0;rn;rnrnmain()rnrn Person('L',23,171,60);rn printPerson();rn return 0;rnrn编译器给的错误信息是:Function 'printPerson' should have a prototype
请问这个语句错在哪里?
SELECT E.CourseID, E.Grade, S.FName, S.LName FROM Assignment_DB.ENROLLED AS E INNER JOIN Assignment_DB.STUDENT AS S ON E.StudentID=S.StudentIDrnrn在用JDBC做数据检索,但是发现这个搜索语句老报错:“SQL command not properly ended.”rn请问问题出在哪里呢?
请问:这个SQL错在哪里???
CREATE TABLE COUNT_PERS AS (SELECT DISTINCT(A01.pers_code)rn FROM a01rn WHERE a0101 = 'fishxie' AND rn (A01.A0157B LIKE '200%' ORrn A01.A0157B LIKE '200005%' ORrn A01.A0157B LIKE '200200%' ORrn A01.A0157B LIKE 'A00%'))
请问这个win32错在哪里
[img=https://img-bbs.csdn.net/upload/201604/25/1461596641_71923.png][/img]
请问这个查询错在哪里?
请问这样的一个查询语句错在哪里?为什么老是弹出请输入数据的窗口??rnrnSELECT *rnFROM course INNER JOIN grade ON course.cno=grade.cno;
请问这个存储过程错在哪里?
create proc CheckLoginrn(rn @userName varchar(10),rn @userPwd varchar(10),rn @result varchar(50) outputrn)rnasrnbeginrn declare @number intrn set @number=(select count(*) from login where userName=@userName and userPwd=@userPwd)rn if(@number <> 0)rn @result='success'rn elsern @result='fail'rnendrnrn服务器: 消息 170,级别 15,状态 1,过程 CheckLogin,行 12rn第 12 行: '@result' 附近有语法错误。
请问这个宏错在哪里?
#define MYPEN(pDC, ps, w, nclr) CPen MYPEN(ps, w, nclr); \rn CPen *pOldPen = pDC->SelectObject(&MYPEN);rnrn#define DEL_MYPEN(pDC) pDC->SelectObject(pOldPen); \rn MYPEN.DeleteObject();rnrn MYPEN(pDC, PS_SOLID, 2, RGB(255, 255, 0))rn for (k = 0; k < COURSE_AMNT; k++)rn rn pDC->MoveTo(0, 0);rn pDC->LineTo(100, 100*k);rn rn DEL_MYPEN(pDC)rnrn MYPEN(pDC, PS_SOLID, 2, RGB(255, 0, 255)))rn for (k = 0; k < COURSE_AMNT; k++)rn rn pDC->MoveTo(0, 0);rn pDC->LineTo(100, 10*k);rn rn DEL_MYPEN(pDC)rnrn MYPEN(pDC, PS_SOLID, 2, RGB(0, 255, 255)))rn for (k = 0; k < COURSE_AMNT; k++)rn rn pDC->MoveTo(0, 0);rn pDC->LineTo(10, 100*k);rn rn DEL_MYPEN(pDC)rnrn MYPEN(pDC, PS_SOLID, 2, YELLOW_CLR)rn for (k = 0; k < COURSE_AMNT; k++)rn rn pDC->MoveTo(0, 0);rn pDC->LineTo(10, 100*k);rn rn DEL_MYPEN(pDC)rn
相关热词 c# login 居中 c# 考试软件 c# 自然语言分析 c# 分段读取文件 c# 泛型反射 c#打断点 c# 时间转多少秒 c# 线程函数加参数 c# modbus 读取 c#查询集合表