C++ vector Storing double type numbers
#include <iostream> #include <cmath> #include <vector> int main()/*w ww . ja va 2s. c o m*/ { int n {}; std::cout << "Enter the number of vector elements: "; std::cin >> n; auto values = new std::vector<double>(n); for (unsigned long long i {}; i < n; ++i) (*values)[static_cast<int>(i)] = 1.0 / ((i + 1)*(i + 1)); double sum {}; for (auto value : *(values)) sum += value; std::cout << "Result is " << std::sqrt(6.0*sum) << std::endl; delete values;// It's not an array this time! }