这个C 语言程序错在哪,为什么不能通过编译系统

[复制链接]
查看11 | 回复3 | 2007-3-23 23:58:34 | 显示全部楼层 |阅读模式
用公式,效率高:#include #include double sum(double x, int n){ return n != 1 ? x + n * (1 - pow(n, x)) / (1 - n) : x;}int main(){ printf("%.lf\n", sum(1,1)); printf("%.lf\n", sum(2,2)); printf("%.lf\n", sum(3,3)); printf("%.lf\n", sum(4,4));}
回复

使用道具 举报

千问 | 2007-3-23 23:58:34 | 显示全部楼层
给你一个正确的程序:#includemain(){int k,n,s=0,f=1,x;scanf(\"%d,%d\",&x,&n);printf(\"%d,%d\\n\",x,n);for(k=1;k<=n;k++){f*=x;s+=f;}printf(\"%d\\n\",s);}
回复

使用道具 举报

千问 | 2007-3-23 23:58:34 | 显示全部楼层
C语言不能函数嵌套,也就是说在一个函数中不能再定义函数,你的fun函数是在主函数中定义的
回复

使用道具 举报

千问 | 2007-3-23 23:58:34 | 显示全部楼层
fun重复定义了,当然会出错...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行