How do I get the 10 lowest values in an array? [closed] - c++

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
I have an array of type double. How do I get the 10 lowest values?
double values[1000];
This is what I've come up before:
double similar[num_img];
copy(begin(values), end(values), begin(similar)); //copy values to another variable
int elements = sizeof(similar) / sizeof(similar[0]);
sort(similar, similar + elements);
So that I could get the 10 values. But what I'm actually after is the indices.. So sorting it would not help, I guess.

Sort the array and grab the first 10 elements (values[0] through values[9]).

Related

subscriptesd value is neither array nor pointer nor vector [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 2 months ago.
Improve this question
I try to distribute the companies by months according to their value.
void obtener_distribucion_por_meses(empresaibex t_empresasibex[],int total_empresas, int mes_actual){
int i,valoresmes;
for(i=0;i<mes_actual;i++){
valoresmes[i]=aleatorio;
}
}
Since this is non-english, I can't exactly understand what you're trying, but you can't access to valoresmes, which is an int, with an index. Maybe you were trying to do it with your array t_empresasibex ?

Problems with division in c++ [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I am using c++ on my project. However, when I try to make a simple division, it gives me a weird number.
for:
1.0 / 2.0 = -107374176.
1.0 / 3.0 = -107374176.
1 / 3 = -107374176.
any idea why this is happening?
0xCCCCCCCC, a typical value used for uninitialized memory, interpreted as a 32-bit float, equals -107374176. You're printing an uninitialized float value.

Check for even or odd [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
Given N amd M how to check whether floor value of N!/M will be even value or odd value where N can go upto 10^5 and M can go upto 10^18.
Please help to check this condition in efficient way.
EDIT
My attempt : I first think of breaking N!=(2^a)(some odd value) and similarly for M but as the odd value of N! can be very large so i was thinking of some better solution.

Modifying elements of a string vector in c++ [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
How can I append a string to an element of an string vector?
I consistently get segmentation fault.
Appending str to the ith element of vec:
vec[i] += str;
Assuming vec is something like a std::vector<std::string> and the ith element exists.

Finding value of int x [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
int x;
x=x+30;
cout << x;
the output will be 33, why is it so?
I didn't even declare x as 3.
Can someone guides me? Thanks!
Using an uninitialized variable is undefined behavior. You got 33 due to an unreliable sequence of implementation quirks. The program is free to produce any value at all, fail to compile, or hire an assassin to stab you.
In C++, variables are given space (memory allocation) by default equal to the size of the variable, but they are not given values by default.