Content deleted Content added
Undid revision 594155042 by Myconix (talk) -- this is not RosettaCode, see Template:Example farm for rationale |
Add c++ |
||
Line 38:
The problem with the usually specified function is that the term <code>5*t^3</code> gives overflows in almost all languages for very large negative values.
==[[C++]] implementation==
This shows a C++ implementation equivalent to the above ALGOL 60. Evolution of C++98, C++11 and C++14 is showed as well.
<syntaxhighlight lang="cpp">
#include <algorithm>
#include <cmath>
#include <iostream>
double f(int n) { // in C++14, return type can be inferred using "auto f(int n)"
return sqrt(abs(n)) + 5*n*n*n;
}
int main() {
const int N = 11; // in C++11, can be declared as "constexpr auto N = 11;"
int S[N]; // in C++11, can be declared as "std::array<int, N> S;
for(int i = 0; i < N; ++i) {
std::cin >> S[i];
}
std::reverse(S, S+N); // in C++11, can be used as "std::reverse(begin(S), end(S));"
for(int i = 0; i < N; ++i) { // in C++11, can be used as "for(auto i : S) {"
double y = f(i);
if(y > 400) {
std::cout << i << " TOO LARGE\n";
}
else {
std::cout << y << '\n';
}
}
}
</syntaxhighlight>
==References==
* "The Early Development of Programming Languages" in ''A History of Computing in the Twentieth Century'', New York, Academic Press, 1980. ISBN 0-12-491650-3 (Reprinted in Knuth, Donald E., ''et al.'', ''Selected Papers on Computer Languages'', Stanford, CA, CSLI, 2003. ISBN 1-57586-382-0) [http://www.textfiles.com/bitsavers/pdf/stanford/cs_techReports/STAN-CS-76-562_EarlyDevelPgmgLang_Aug76.pdf (typewritten draft, August 1976)]
|