如何解决带无符号整数的向量
我的老师给我分配了这个问题,我必须在其中创建斐波那契的代码,我知道如何制作斐波那契,但我真的不知道我将如何处理他给出并说的这段代码它必须在我的代码中。
谁能写出满足这个要求的代码? 我真的很想了解,但我试过用谷歌搜索,看一些教程,但不明白这是要做什么。
#include "function.h"
std::vector<unsigned int> fib_below_n( unsigned int n )
{
// ALL: add your code here
// ALL: This is just a STUB. Change the RETURN for what you judge right.
return std::vector<unsigned int>{};
}
解决方法
这里有更多详细信息可以帮助您入门:
std::vector<unsigned int> retval;
unsigned prev= 1;
unsigned current = 1;
// loop to generate fibonacci numbers
while (current < n) {
retval.push_back (current); /// <<<<< here
// >> generate the next number
}
return retval;
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。