This would be shorter, but I tend to think the best code, in any project, is the most readable and the most maintainable; that is, I prefer clarity over brevity if there's a choice.
It's usually helpful to look carefully at the problem and solve exactly what's for and no more. So while my solution is pedantic, I hope it illustrates the idea.
- Since you don't do anything with the numbers, there's no need for an array.
- Unless you really need the output to go the screen then there's no need to delay printing it:
1 2 3 4 5 6 7 8 9 10
#include <iostream>
int main(){
int n;
std::cout << "Enter three numbers:\n";
for (int i=0; i<3; ++i) {
std::cin >> n;
std::cout << n << '\n';
}
}
To go even further, you could just print "Enter three numbers:\n" and then copy cin to cout.