今天做南邮编程在线的编程题,编程首先计算Fibonacci数列1,1,2,3,5,8,13,21,......的前n项(n不超过40)存入一维整型数组f中,再按%12d的格式输出每项的值,每6项换一行。

#include<stdio.h>
int main()
{
int f[40],n,count=0;
scanf("%d",&n);
f[0]=f[1]=1;
for(int i=2;i<n;i++)
{
f[i]=f[i-1]+f[i-2];
}

for( i=0;i<n;i++)
{
printf("%12d",f[i]);
count++;
if(count%6==0)
printf("\n");
}
printf("\n");
return 0;
}

此程序在VC++6.0,codeblock等里面可以正确编译,但在网站的编译器里面却不行。然后上网百度了下,有大神的博客已经解决了。但是别人不允许转载,想看的自己可以百度看看。

将for(int i=2;i<n;i++)中的int定义提到外面,变为int i;

for(int i=2;i<n;i++)

原因是gcc的标准不同导致for循环的使用有差异。

下面为修改正确的程序

#include<stdio.h>
int main()
{
int f[40],n,i,count=0;
scanf("%d",&n);
f[0]=f[1]=1;
for( i=2;i<n;i++)
{
f[i]=f[i-1]+f[i-2];
}

for( i=0;i<n;i++)
{
printf("%12d",f[i]);
count++;
if(count%6==0)
printf("\n");
}
printf("\n");
return 0;
}

for’ loop initial declarations are only allowed in C99 mode的更多相关文章

  1. error: ‘for’ loop initial declarations are only allowed in C99 mode

    比如写出下面这段程序: for (int i = 0; i < n; ++i) do_something(); 然后用gcc编译,会报 ‘for’ loop initial declaratio ...

  2. ‘for’ loop initial declarations are only allowed in C99 mode

    #include <stdio.h>int main(){ for(int i=0;i<10;i++){ printf("\n%d",i); } return 0 ...

  3. error: 'for' loop initial declarations are only allowed in C99 mode

    error: 'for' loop initial declarations are only allowed in C99 mode   出现错误: error: 'for' loop initia ...

  4. error: &#39;for&#39; loop initial declarations are only allowed in C99 mode

    error: 'for' loop initial declarations are only allowed in C99 mode 使用gcc编译代码是报出 error: 'for' loop i ...

  5. 【异常】‘for’ loop initial declarations are only allowed in C99 mode

    1 Python版本导致的异常 /root/Python-3.5.7/Modules/_pickle.c: In function ‘PyMemoTable_Copy’: /root/Python-3 ...

  6. Win下GCC报错 error: ‘for’ loop initial declarations are only allowed in C99 mode

    ##报错## 用GCC编译for循环会出现以下错误 error: 'for' loop initial declarations are only allowed in C99 mode 如图所示: ...

  7. [Error] 'for' loop initial declarations are only allowed in C99 or C11 mode

    #include <stdio.h> #include <stdlib.h> #define LIST_INIT_SIZE 100 //线性表存储空间的初始分配量 #defin ...

  8. error: ‘for’ loop initial declarations are only allowed in

    使用gcc,出现如下错误: thread_join.c:7:5: error: 'for' loop initial declarations are only allowed in C99 mode ...

  9. 'for' loop initial declarations are only allo

    linux系统下的c编程与windows有所不同,如果你在用gcc编译代码的时候提示‘for’ loop initial declarations are only allowed in C99 mo ...

随机推荐

  1. vue中数据双向绑定注意点

    最近一个vue和element的项目中遇到了一个问题: 动态生成的对象进行双向绑定是失败 直接贴代码: <el-form :model="addClass" :rules=& ...

  2. 实现一个javascript手势库 -- base-gesture.js

    现在移动端这么普及呢,我们在手机上可以操作更多了.对于网页来说实现一些丰富的操作感觉也是非常有必要的,对吧(如果你仅仅需要click,,那就当我没说咯...)~~比如实现上下,左右滑动,点击之类的,加 ...

  3. 20170422早会训话,ps:程序出现两次BUG,领导很生气

    针对这种问题: 要讲3点 1.有没有拖团队后腿: 作为一名前端开发人员,对于前端开发的任务,我能够在第一时间完成,保证时间进度,但光做到这一点是不够的,不能只讲究任务,不考虑结果,会不会出现问题造成其 ...

  4. 关于MATLAB处理大数据坐标文件2017528

    第一次提交数据 增加了部分特征 3000数据测试中得分99 但是10万数据出现过拟化现象,正确率下降 总结:1.某些特征数据本身波动不大应该考虑放弃 2.一些特征虽然表面觉得差异显而易见,但是数据表达 ...

  5. 【LeetCode】144. Binary Tree Preorder Traversal

    题目: Given a binary tree, return the preorder traversal of its nodes' values. For example:Given binar ...

  6. 如何简单的实现新手引导之UGUI篇

    一个完整的游戏项目肯定是要做新手引导的,而引导做的好坏可能会影响玩家的留存.那么怎么简单的实现个简有效的引导呢!先不说废话,先看看效果,这是一个基于UGUI做的一个简单的引导! 怎么样,看着是那么回事 ...

  7. 排序算法总结及Java实现

    1. 整体介绍 分类 排序大的分类可以分为两种,内排序和外排序.在排序过程中,全部记录存放在内存,则称为内排序,如果排序过程中需要使用外存,则称为外排序.主要需要理解的都是内排序算法: 内排序可以分为 ...

  8. SQL语言-----数据操作

    数据操作 增加数据,insert into 标准格式 insert into 表名 (字段的列表)value(数据列表): 使用set insert into 表名 set 字段1=值,2.....: ...

  9. SpringEL 表达式错误记录

    原因暂时未知....

  10. IIS 部署WCF服务注意事项

    IIS部署WCF服务的时候经常会出现如下错误: System.ServiceModel.EndpointNotFoundException”类型的未经处理的异常在 WinformWcfHost.exe ...