for’ loop initial declarations are only allowed in C99 mode
今天做南邮编程在线的编程题,编程首先计算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的更多相关文章
- 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 ...
- ‘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 ...
- 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 ...
- error: 'for' 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 ...
- 【异常】‘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 ...
- 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 如图所示: ...
- [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 ...
- 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 ...
- 'for' loop initial declarations are only allo
linux系统下的c编程与windows有所不同,如果你在用gcc编译代码的时候提示‘for’ loop initial declarations are only allowed in C99 mo ...
随机推荐
- Redis中的数据对象
redis对象 redis中有五种常用对象 我们所说的对象的类型大多是值的类型,键的类型大多是字符串对象,值得类型大概有以下几种,但是无论哪种都是基于redisObject实现的 redisObjec ...
- php后台拼接输出table表格
<?php header("Content-type:text/html;charset=utf-8"); $str=''; $str.='<table border= ...
- thinkphp带查询条件的分页
<!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8& ...
- alt和title的区别与用法
alt和title的是我们工作中经常用到这两个属性,但是一直没有总结他们的区别.现在就对他们两个的用法做一下总结.相同点:他们都会飘出一个小浮层,显示文本内容.不同点:1.alt只能是元素的属性,而t ...
- 【Android Developers Training】 41. 向另一台设备发送文件
注:本文翻译自Google官方的Android Developers Training文档,译者技术一般,由于喜爱安卓而产生了翻译的念头,纯属个人兴趣爱好. 原文链接:http://developer ...
- C++ inline函数与编译器设置
1. 经过测试#define与inline的速度几乎没有区别. 2. inline函数更为安全,有效避免了#define二义性问题.inline是真正的函数,而#define只是在字符串意义上的宏替换 ...
- htm5
htm5在html4.0. xhtm1.0的基础上增加了音频.视频.拖拽等功能,不过,htmL5,还在完善中,不过大部分浏览器都已经支持了部分功能. 兼容性: 最新版本的 Safari.Chrome. ...
- Selective Search for Object Recognition 论文笔记【图片目标分割】
这篇笔记,仅仅是对选择性算法介绍一下原理性知识,不对公式进行推倒. 前言: 这篇论文介绍的是,如果快速的找到的可能是物体目标的区域,不像使用传统的滑动窗口来暴力进行区域识别.这里是使用算法从多个维度对 ...
- 【前端】一步一步使用webpack+react+scss脚手架重构项目
前言 前几天做了一个项目:[node]记录项目的开始与完成——pipeline_kafka流式数据库管理项目:因为开发时间紧迫,浅略的使用了一下react,感觉这个ui库非常的符合我的口味,现在趁着有 ...
- Python 3从入门到精通01-环境搭建
本系列开始介绍Python3的基础教程,为什么要选中Python 3呢?因为最近看到一些资料和课程,都是Python 3授课的,例如,大数据,机器学习,数据挖掘等等:还有一个目的,我想彻底地,系统地学 ...