Answer Posted / jeena
/*Code to write second Minimum Number*/
int[] intarr = { 2, 5, 1, 8, 3, 6, 0, 4, 3, 2, 78, 1, 8 };
int intminval = 0, intsecondminval = 0;
for (int i = 0; i < intarr.Length; i++)
{
if (i == 0)
{
intminval = intsecondminval = intarr[i];
}
else
{
if (intarr[i] < intminval)
{
intsecondminval = intminval;
intminval = intarr[i];
}
else if (intminval == intsecondminval && intarr[i] > intminval)
{
// this conditon is to handle the case
//where the array contains only 2 values
// for e.g. {1,1,2,1,2,2,1}
intsecondminval = intarr[i];
}
}
}
| Is This Answer Correct ? | 5 Yes | 6 No |
Post New Answer View All Answers
Explain how functions are classified in C++ ?
What is the maximum combined length of command line arguments including the space between adjacent arguments?
Why c++ is so important?
What is a class definition?
What is null pointer and void pointer?
How can virtual functions in c++ be implemented?
What do you mean by translation unit?
Describe delete operator?
How we can differentiate between a pre and post increment operators during overloading?
What is iterator in c++?
Describe the setting up of my member functions to avoid overriding by the derived class?
When do we use copy constructors?
How the keyword struct is different from the keyword class in c++?
Why do we use structure in c++?
Is c++ a difficult language?