. #include <iostream>
int main()
{
std::cout << "Enter 10 numbers: ";
constint MAXNUM = 10;
int fmax[MAXNUM] = {0}; // initialization of the array elements to zero
int maxNum = 0, location;
for(int i = 0; i < MAXNUM; i++) {
std::cin >> fmax[i];
if(fmax[i] > maxNum) {
maxNum = fmax[i];
location = i;
}
}
std::cout << "The maximum number is " << maxNum << std::endl;
std::cout << "The location of the number is " << location << std::endl;
return 0;
}
Have you googled it? If not, you should consider it.
You can start by counting the number of nested loops. Typically no loops indicates O(1), one loop O(1), more, higher complexity, and short cuts lower the complexity. But that's unofficial and probably not even write, but it's a reasonable guide.
one loop O(n) I think you meant. But these kind of generalizations are not safe:
for(i = 0; i < 10; i++)
^^ this could be O(1) //constant time: it runs 10 times or O(n) if there is some meaning to '10' in terms of what you are measuring. If n is 1234, you would say O(1) if you can't relate 10 to 1234 in some way relevant to the problem it solves. If n is 10, or 20 and it looks at every other one, or something, you may argue O(n).
Analysis can be difficult but at the end of the day you are trying to count how many times you do work** vs how much input you have, and express that in a notation everyone uses to make it clear what is going on.
** this can be defined to suit your needs, eg how many comparisons or how many swaps or whatever are done.