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 ...
随机推荐
- HTML特殊布局--------双飞翼布局
今天看到以前写的一篇布局的例子分享给大家,双飞翼布局. 什么是双飞翼布局?? 1.三列布局,中间宽度自适应,两边固定宽度; 2.中间栏在浏览器中优先展示渲染: 双飞翼布局的原理: 中间的盒子定100% ...
- jeecg项目子窗口获得父窗口元素id
jeecg项目子窗口获得父窗口元素id, var parentWin = frameElement.api.opener;alert($(parentWin.document).find(" ...
- StructureMap经典的IoC/DI容器
StructureMap是一款很老的IoC/DI容器,从2004年.NET 1.1支持至今. 一个使用例子 //创建业务接口 public interface IDispatchService { } ...
- 使用PHP二维码生成类库PHP QR Code生成二维码
<?php include 'phpqrcode.php'; $value = 'http://www.helloweba.com'; //二维码内容 $errorCorrectionLevel ...
- mysql时间戳与日期格式的相互转换
1.UNIX时间戳转换为日期用函数: FROM_UNIXTIME()[sql] view plain copyselect FROM_UNIXTIME(1156219870); 输出:2006-08- ...
- SpringMvc+Spring3+MyBatis整合
1.MyBatis 例子 首先,单独使用MyBatis时: import java.io.IOException; import java.io.Reader; import org.apache.i ...
- 一张图告诉你 canvas 中的 miterLimit 代表着什么
一图胜千言, 图中有一条路径path, 沿着路径描了一条宽度为 width 的边, miterLimit 代表的是, 比例 ab/ac, 其中ac的长度为 1/2 width 来看 mdn 上的描述, ...
- Django开发的基于markdown的博客开源
PiperMarkdown Blog for Django1.11,Python 3.6,based on Markdown,网址,希望大家能给个star,谢谢! 什么是PiperMarkdown 这 ...
- MyBatis源码解析【1】准备工作
终于迎来了这一天,我觉得现在的我在经历了长时间的学习和开发之后有了一定的经验,所以准备开始学习源码. 今天我将做好充足的准备,在接下来的一个月中,努力的爬过这座大山.(可能不用一个月,但是我觉得需要仔 ...
- vijos1034题解
题目: 若某个家族人员过于庞大,要判断两个是否是亲戚,确实还很不容易,现在给出某个亲戚关系图,求任意给出的两个人是否具有亲戚关系. 规定:x和y是亲戚,y和z是亲戚,那么x和z也是亲戚.如果x,y是亲 ...