鱼C论坛

 找回密码
 立即注册
查看: 3754|回复: 1

大大们帮我看看代码,一个斐波那契数列,在加了if以后报错了。不知道问题在哪里?

[复制链接]
发表于 2013-7-9 00:17:15 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
#include "stdio.h"
#include "math.h"

void main()
{
        int f1=1,f2=1,fn=1,i,n;
        printf("input the number of n which is the nth number of fibonacci series");
        scanf("%d",&n);
        for(i=2; i<n ;i++)
        {
                if n<0
                {
                        printf("error");
                        break;
                }
                fn=f1+f2;
                f1=f2;
                f2=fn;
        }
        printf("%d\n",fn);
}

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2013-7-9 00:30:37 | 显示全部楼层
自己学习了,忘记加括号的悲剧。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-7-19 13:22

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表