今天做南邮编程在线的编程题,编程首先计算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. [USACO4.2]草地排水Drainage Ditches

    题目背景 在农夫约翰的农场上,每逢下雨,贝茜最喜欢的三叶草地就积聚了一潭水.这意味着草地被水淹没了,并且小草 要继续生长还要花相当长一段时间.因此,农夫约翰修建了一套排水系统来使贝茜的草地免除被大水淹 ...

  2. Bash On Windows的学习

    Bash On Windows的学习 Bash On Windows的卸载 删除软件和设置:在 cmd 运行lxrun /uninstall 删除所有文件:在cmd中运行lxrun /uninstal ...

  3. Loadrunner12解决无法录制chrome及脚本为空问题

    首先,得安装LR12,一般用LR12录制,由于未破解,用LR11跑并发. LR12官方文档说明里是支持chrome及火狐的,但是实际录制起来,还是有一定的问题,目前发现的问题主要有两个: (1)LR录 ...

  4. RPM基础知识

    RPM包命名原则 httpd-2.2.15-15.el6.centos.1.i686.rpm httpd       软件包名 2.2.15       软件版本 15      软件发布的次数 el ...

  5. 网络组Network Teaming

    网络组team:是将多个网卡聚合在一起,从而实现容错和提高吞吐量 1 创建网络组接口 nmcli connection add type team con-name TEAMname ifname I ...

  6. js循环处理后台返回的json数组

    <script type="text/javascript"> function gongdan_search(elm){ var dangqian_value=$(e ...

  7. Spring Boot 集成swagger实例

    原文:https://github.com/x113773/testall/issues/5 1. 首先添加maven依赖``` <dependency> <groupId>i ...

  8. Ubuntu+OpenCV2.4.11+ CodeBlocks 配置

    1.OpenCV 与 CodeBlocks 的安装都比较简单,好多教程. 参考http://www.cnblogs.com/lyutian/p/4425956.html 安装opencv. Codeb ...

  9. 从Android源码的角度分析Binder机制

    欢迎访问我的个人博客,原文链接:http://wensibo.top/2017/07/03/Binder/ ,未经允许不得转载! 前言 大家好,好久不见,距离上篇文章已经有35天之久了,因为身体不舒服 ...

  10. git的使用[转]

    本节内容 github介绍 安装 仓库创建& 提交代码 代码回滚 工作区和暂存区 撤销修改 删除操作 远程仓库 分支管理 多人协作 github使用 忽略特殊文件.gitignore 为什么要 ...