| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 942 人关注过本帖
标题:帮我看看程序哪错了。。。。
只看楼主 加入收藏
QQ714780440
Rank: 1
等 级:新手上路
帖 子:15
专家分:1
注 册:2011-4-27
结帖率:100%
收藏
 问题点数:0 回复次数:10 
帮我看看程序哪错了。。。。
#include <stdio.h>
void main()
{
    int max(int 5,int 8);
    int a,b,c;
    scanf("%d,%d",&a,&b);
    c=max(a,b);
    printf("max=%d\n",c);
}
int max(int 5,int 8)
{
    int z;
    if (5>8) z=x
    else z=y
    return(z)
}
在VC6.0里运行不了
--------------------Configuration: 5 - Win32 Debug--------------------
Compiling...
5.c
C:\Documents and Settings\Administrator\5.c(4) : error C2143: syntax error : missing ')' before 'constant'
C:\Documents and Settings\Administrator\5.c(4) : error C2143: syntax error : missing ';' before 'constant'
C:\Documents and Settings\Administrator\5.c(4) : error C2059: syntax error : 'type'
C:\Documents and Settings\Administrator\5.c(4) : error C2059: syntax error : ')'
C:\Documents and Settings\Administrator\5.c(5) : error C2143: syntax error : missing ';' before 'type'
C:\Documents and Settings\Administrator\5.c(6) : error C2065: 'a' : undeclared identifier
C:\Documents and Settings\Administrator\5.c(6) : error C2065: 'b' : undeclared identifier
C:\Documents and Settings\Administrator\5.c(7) : error C2065: 'c' : undeclared identifier
C:\Documents and Settings\Administrator\5.c(7) : warning C4020: 'max' : too many actual parameters
C:\Documents and Settings\Administrator\5.c(10) : error C2143: syntax error : missing ')' before 'constant'
C:\Documents and Settings\Administrator\5.c(10) : error C2143: syntax error : missing '{' before 'constant'
C:\Documents and Settings\Administrator\5.c(10) : error C2059: syntax error : '<Unknown>'
C:\Documents and Settings\Administrator\5.c(10) : error C2059: syntax error : ')'
Error executing cl.exe.

5.exe - 12 error(s), 1 warning(s)
搜索更多相关主题的帖子: return 
2011-04-27 20:11
boxinchao
Rank: 4
等 级:业余侠客
帖 子:51
专家分:231
注 册:2011-4-13
收藏
得分:0 
int 5,int 8
立即数能作为变量使用吗,第一次见
2011-04-27 20:21
QQ714780440
Rank: 1
等 级:新手上路
帖 子:15
专家分:1
注 册:2011-4-27
收藏
得分:0 
回复 2楼 boxinchao
我剛開始學C程,麻煩你說詳細點....
2011-04-27 21:42
唯我独魔
Rank: 8Rank: 8
等 级:蝙蝠侠
帖 子:176
专家分:782
注 册:2011-4-13
收藏
得分:0 
回复 2楼 boxinchao
就是int 后面只能是变量,不能是常量,如你的5 8
2011-04-27 21:55
hjywyj
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:3
帖 子:1114
专家分:2611
注 册:2010-4-14
收藏
得分:0 
int max(int 5,int 8)
{
    int z;
    if (5>8) z=x
    else z=y
    return(z)
}
把5,8改为x,y.
2011-04-28 07:17
因为曾今年少
Rank: 2
等 级:论坛游民
帖 子:131
专家分:62
注 册:2011-4-13
收藏
得分:0 
程序代码:
#include <stdio.h>
void main()
{
   //int max(int 5,int 8 );//这一个语句没有必要啦
    int a,b,c;
    scanf("%d,%d",&a,&b);
    c=max(a,b);
    printf("max=%d\n",c);
}
int max(int x,int y)
{
    int z;
    if (x>y) z=x;
    else z=y;
    return z;
}
你看看对不对啦
2011-04-28 08:01
jia877181835
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2011-5-1
收藏
得分:0 
标示符的定义?
2011-05-01 16:50
ansic
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:恍惚窈冥
等 级:城市猎人
帖 子:1543
专家分:5367
注 册:2011-2-15
收藏
得分:0 
以下是引用因为曾今年少在2011-4-28 08:01:26的发言:

#include <stdio.h>
void main()
{
   //int max(int 5,int 8 );//这一个语句没有必要啦
    int max(int a,int b); //声明函数原型。
    int a,b,c;
    scanf("%d,%d",&a,&b);
    c=max(a,b);
    printf("max=%d\n",c);
}
int max(int x,int y)
{
    int z;
    if (x>y) z=x;
    else z=y;
    return z;
}你看看对不对啦

从标准,规范的角度来看, 加上函数原型声明是个好习惯

善人者,不善人之师;不善人者,善人之资。不贵其师,不爱其资,虽智大迷。
2011-05-01 16:58
编程的乐趣
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:1
帖 子:229
专家分:1027
注 册:2011-4-4
收藏
得分:0 
怎么能把常量声明为整型呢
2011-05-01 18:37
aaaliudebao
Rank: 2
等 级:论坛游民
帖 子:18
专家分:23
注 册:2011-3-7
收藏
得分:0 
int max(int 5,int 8);
这条是函数体的声明部分,
前面的"int"是 返回值类型,
"max"是 函数名,
括弧中是 形式参数列表,形参一定是变量的,
如果你想输入两个常量进行比较大小可以改成:
#include <stdio.h>
void 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);
}
int max(int x,int y)
{
    int z;
    if (x>y) z=x
    else z=y
    return(z)
}
运行时输入两个整型常量如:5,8   输出:8
如果你想直接给两个数判断大小可以这样写:
#include <stdio.h>
void main()
{
    int max(int x,int y);
    int a=5,b=8,c;
    c=max(a,b);
    printf("max=%d\n",c);
}
int max(int x,int y)
{
    int z;
    if (x>y) z=x
    else z=y
    return(z)
}
运行直接输出:8

2011-05-01 19:25
快速回复:帮我看看程序哪错了。。。。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021386 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved