3 Answers
3

efficiency

Yes, this can be improved.

One obvious problem is that you're re-computing your average and your standard deviation on every iteration of a loop, even though only the last result (after the last iteration) is ever actually used.

Use of pow

I'd avoid using pow to compute a square. It often imposes quite a bit of overhead, so pow(deviation[i], 2) will often be substantially slower than deviation[i]*deviation[i].

Formatting

Looking at the code more generally, you really need to fix your indentation.

std::endl

I would advise against using std::end. Normally, you just want '\n', which also gives you a new line, but will nearly always be (much) faster. In the case above, it won't make much difference, but if you're writing a lot of data to a file (for example) the difference can get very large, very quickly (e.g., a slowdown of 8:1 or 10:1 is fairly typical).

It is generally considered a poor idea to import all names from a namespace (with some exceptions, such as the namespaces for literals, or if you are actually implementing that namespace). It creates a risk of identifier clashes that could bite you when you compile against future C++ standards.

double dev = 0;

Unused variable.

system( "pause" );

sh: 1: pause: not found

And you didn't include <cstdlib> for this, anyway.

Arithmetic: there's a subtle problem in accumulating int values into a double, which you won't see on such small input sets. As the double re-scales itself, less and less of each int is significant to the sum. For large input sets, you may need to accumulate into a long (or unsigned long if your inputs can't be negative) and only add that to sum when it's about to overflow:

General: it's a good idea to separate your printing from your algorithm. Create a function to do the computation; then your main() should call it appropriately and print the output. To get you started: