| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 627 人关注过本帖
标题:一道数组相关问题
取消只看楼主 加入收藏
sunkiist
Rank: 2
等 级:论坛游民
帖 子:12
专家分:20
注 册:2015-11-9
结帖率:50%
收藏
已结贴  问题点数:20 回复次数:4 
一道数组相关问题
图片附件: 游客没有浏览图片的权限,请 登录注册

题目如上,我的想法是用数组实现,编译通过了,但是黑框缺无法实现,以下是程序。

#include<stdio.h>
int main(void)
{
    int i, n;
    int a[13] = { 0, 1, 2 };
    printf("Input n (13>=n>=2): ");
    scanf("%d", &n);
    for (i = 2; i < 13; i++)
    {
        a[i + 1] = 2 * a[i] + a[i - 1] * a[i - 2];
    }
    if (n == i)
        printf("\nf(%d)=%d\n", n, a[i]);
    return 0;
}
2015-11-09 18:57
sunkiist
Rank: 2
等 级:论坛游民
帖 子:12
专家分:20
注 册:2015-11-9
收藏
得分:0 
回复 2楼 林月儿
还是有点想请教,既然n=i那么是a[i]或者a[n]不是应该一样的么?
2015-11-10 17:25
sunkiist
Rank: 2
等 级:论坛游民
帖 子:12
专家分:20
注 册:2015-11-9
收藏
得分:0 
回复 3楼 rjsp
很谢谢!我一想0-13还真是14个,我真是太粗心了= =。虽然几个头文件还没学,不过记下了,以后肯定还有用。
2015-11-10 17:29
sunkiist
Rank: 2
等 级:论坛游民
帖 子:12
专家分:20
注 册:2015-11-9
收藏
得分:0 
回复 7楼 林月儿
我好像明白了,是不是那个if要放到for语句里面?否则就不能遍历判断

[此贴子已经被作者于2015-11-10 17:53编辑过]

2015-11-10 17:51
sunkiist
Rank: 2
等 级:论坛游民
帖 子:12
专家分:20
注 册:2015-11-9
收藏
得分:0 
回复 9楼 林月儿
我试了试,在未触及两个溢出int的值的时候把if放入for循环确实达到了我想要的目的。目前还无法很灵活的应用上面那位的几个函数。所以我想是用double实现,又出现了:C:\Users\Administrator\Desktop\遇到的问题\Cpp1.cpp(30) : error C2108: subscript is not of integral type
C:\Users\Administrator\Desktop\遇到的问题\Cpp1.cpp(30) : error C2108: subscript is not of integral type
C:\Users\Administrator\Desktop\遇到的问题\Cpp1.cpp(30) : error C2297: '*' : illegal, right operand has type 'double *'
C:\Users\Administrator\Desktop\遇到的问题\Cpp1.cpp(30) : error C2108: subscript is not of integral type
C:\Users\Administrator\Desktop\遇到的问题\Cpp1.cpp(30) : error C2108: subscript is not of integral type
C:\Users\Administrator\Desktop\遇到的问题\Cpp1.cpp(30) : error C2296: '*' : illegal, left operand has type 'double *'
C:\Users\Administrator\Desktop\遇到的问题\Cpp1.cpp(30) : error C2297: '*' : illegal, right operand has type 'double *'
C:\Users\Administrator\Desktop\遇到的问题\Cpp1.cpp(32) : error C2108: subscript is not of integral type
如下的错误,我搜索了一下类似错误都是pow()函数不能返回double值,可我没用pow()怎么出现相关错误,如果您有时间能指教以下用double怎么写么?
2015-11-10 18:10
快速回复:一道数组相关问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014235 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved