我编写了一个程序,用户可以在向量中输入任意数量的值,它应该返回四分位数,但我不断得到"向量下标超出范围"错误:
#include "stdafx.h"
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <ios>
#include <vector>
int main () {
using namespace std;
cout << "Enter a list of numbers: ";
vector<double> quantile;
double x;
//invariant: homework contains all the homework grades so far
while (cin >> x)
quantile.push_back(x);
//check that the student entered some homework grades
//typedef vector<double>::size_type vec_sz;
int size = quantile.size();
if (size == 0) {
cout << endl << "You must enter your numbers . "
"Please …Run Code Online (Sandbox Code Playgroud) 我已经看过人们使用的一些代码示例,比如说,std::cout而在其他地方,人们using namespace std;为了简单起见而在顶部.哪个通常是首选?
我正在尝试编写一个简单的程序,打印出1:10整数的第一个Stirling近似值以及1:10阶乘的实际值.这是我的代码:
import math
nf =1
def stirling(n):
return math.sqrt(2*math.pi*n)*(n/math.e)**n
print "n","\t", "Stirling","\t\tFactorial"
for x in range (1,11):
for y in range(1,x):
nf *=y
print x,"\t", stirling(x), "\t\t", nf
Run Code Online (Sandbox Code Playgroud)
我得到了因子的错误输出,我在哪里弄乱了代码?
c++ ×2
coding-style ×1
nth-element ×1
python ×1
python-2.7 ×1
quantile ×1
sorting ×1
vector ×1