今天做南邮编程在线的编程题,编程首先计算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. RPM基础知识

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

  2. 搭建带热更新功能的本地开发node server

    引言 使用webpack有一段时间了,对其中的热更新的大概理解是:对某个模块做了修改,页面只做局部更新而不需要刷新整个页面来进行更新.这样就能节省因为整个页面刷新所产生开销的时间,模块热加载加快了开发 ...

  3. Mongodb基础用法及查询操作[转载]

    插入多条测试数据> for(i=1;i<=1000;i++){... db.blog.insert({"title":i,"content":&qu ...

  4. 关于MongoDB安全事件的一些思考

    刚刚过去的这个周末,各位大数据和数据库从业者想必是被MongoDB的"安全事件"给刷屏了,MongoDB作为当前NoSQL在全球的领军人物,遭到这么大规模的黑客攻击,这也再次让我们 ...

  5. vijos1056题解

    题目: 桌面上放了N个平行于坐标轴的矩形,这N个矩形可能有互相覆盖的部分,求它们组成的图形的面积. 在翻题目时,偶然发现了这道标号为WA的题目. 原来,以前我把一中培训的代码发了上去,却WA了4个点, ...

  6. 虚函数&多态

    对于经常被问到的虚函数和多态的问题,发现百度百科回答得十分详细,所以自己在百度百科上的解释进行总结 一.虚函数 (1)虚函数简介:在某基类中声明为virtual并在一个或者多个派生类中被重新定义的成员 ...

  7. visual Studio 2017 扩展开发(一)《向Visual Studio菜单栏新增一个菜单》

    最近有接触到关于visual studio 2017 扩展的开发,特此记录,也是为了督促自己去深入了解其原理. 开始开发Visual Studio 扩展,在这里我安装了visual studio 20 ...

  8. 说说BroadcastReceiver和ContentProvider

    上一篇说了Activity,Fragment和Service,今天来说说四大组件中的另外两个吧. BroadcastReceiver: 广播在实际开发中非常有用,是各个组件间通讯的利器.广播接收器分为 ...

  9. 论Activity及启动模式,Fragment,Service的使用以及生命周期

    Activity: 这是我总结出来的,介于Activity生命周期相对较多,我在Google官方的生命周期图上又加了几个常用的,便于大家理解 对于ACtivity,先说说启动模式(ps:复制党去死吧, ...

  10. 列表的系列操作(python)

    除了定义和切片外,这里总结下系列的操作: # hanbb come on! names = ["hbb",'tian','bao','cheng'] #Add names.appe ...