无限数组? [英] Boundless Arrays?
本文介绍了无限数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到了一些麻烦。我写了一个代码来找到素数到一个数字,但是由于某种原因,它给我的错误,我没有定义数组中的元素数量,我将使用。是否有可能有一个数组的元素数量不受限制?感谢:)
#include< iostream&
#include< cmath>
#include< fstream>
#include< cstdlib>
using namespace std;
int primer(int max);
int main()
{
system(pause);
return 0;
primer(1000);
}
int primer(int max){
int a [] = 2;
for(int i = 2; i <= max; i ++){
prime = true;
for(int ii = 1; ii <=#a; ii ++){
if i / a [ii] == math.floor(i / a [ii]){
= false;
}
}
if prime == true {
a [#a + 1] = i;
}
}
for(i = 1; i <=#a; i ++){
print(a [i]);
}
}
}
解决方案>
是的。使用 std :: vector
或 std :: deque
。
I'm having some trouble. I wrote a code to find prime numbers up to a number, but for some reason, it gives me the error that I didn't define the number of elements in the array that I will be using. Is it possible to have an array where the number of elements isn't limited? Thanks :)
#include <iostream>
#include <cmath>
#include <fstream>
#include <cstdlib>
using namespace std;
int primer(int max);
int main()
{
system("pause");
return 0;
primer(1000);
}
int primer(int max){
int a[]=2;
for (int i=2;i<=max;i++){
prime=true;
for (int ii=1;ii<=#a;ii++) {
if i/a[ii]==math.floor(i/a[ii]) {
prime=false;
}
}
if prime==true {
a[#a+1]=i;
}
}
for (i=1;i<=#a;i++) {
print(a[i]);
}
}
}
解决方案
Yes. Use a std::vector
or std::deque
.
这篇关于无限数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文