24小时热门版块排行榜    

查看: 461  |  回复: 7
当前只显示满足指定条件的回帖,点击这里查看本话题的所有回帖

longbaoer

新虫 (小有名气)

[交流] 【已解决】高手,帮一下忙 已有3人参与

各位高手,我编的PASCAL三角形,编译的时候出错提示为:
error C2601: 'combination' : local function definitions are illegal
error C2601: 'factorial' : local function definitions are illegal
fatal error C1004: unexpected end of file found
我实在找不出错的原因,请高手指点一下呀,谢谢。
/*pascal_triangle.cpp
*the program display the pascal triangle.
*********************************************/
#include
#include
using namespace std;
/*function prototype*/
int combination(int n,int k);
int factorial(int n);
/*main function*/
void main()
{
        cout<<"the program display the pascal triangle.";
        cout<<"How many lines do you want to generate? ";
    int i,j,k,line,outcome;
        cin>>line;
    for(i=0;i                 for(j=0;j                         cout<<" ";       
                }
                for(k=0;k<=i;k++){
                        outcome=combination(i,k);
                        cout<                 }
                cout<<"\n";
}
/*function:combination*/
int combination(int n,int k)
{
        int result;
        result=factorial(n)/(factorial(k)*factorial(n-k));
        return(result);
}
/*function:factorial*/
int factorial(int n)
{
        int product=1,i;
        for(i=1;i<=n;i++){
                product*=i;       
        }
        return(product);
}

[ Last edited by formleaf on 2010-4-25 at 13:50 ]
回复此楼
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

yythncj


haixing2008(金币+1):多谢交流! 2010-04-22 18:06
local function definitions are illegal


本地函数定义非法
3楼2010-04-22 13:28:06
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
查看全部 8 个回答

yythncj

★ ★ ★
小木虫(金币+0.5):给个红包,谢谢回帖交流
无奈的云(金币+2):谢谢热心参与解答! 2010-04-22 15:05
int combination(int n,int k);
int factorial(int n);

前面这两句去掉就可以了,后面有定义,重复了哦

[ Last edited by yythncj on 2010-4-22 at 13:28 ]
2楼2010-04-22 13:27:22
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

longbaoer

新虫 (小有名气)

isn't that?

int combination(int n,int k);
int factorial(int n);
这两句不能去的,这是function declearation are essential for c/c++ language.
4楼2010-04-23 16:34:44
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

string121

金虫 (小有名气)

★ ★
小木虫(金币+0.5):给个红包,谢谢回帖交流
haixing2008(金币+1):多谢解答! 2010-04-24 10:02
main里少个大括号。
这里:
}
/*function:combination*/
应为:
}
}
/*function:combination*/
5楼2010-04-24 09:58:38
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
普通表情 高级回复 (可上传附件)
信息提示
请填处理意见