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
How would you use qsort() function to sort an array of structures?
What is the header file for setw?
What is a container class? What are the types of container classes in c++?
Explain how would you handle a situation where you cannot call the destructor of a local explicitly?
Why namespace is used in c++?
Describe the advantage of an external iterator.
Is it possible to pass an object of the same class in place of object reference to the copy constructor?
Is c++ built on c?
Which operator cannot overload?
What are manipulators in c++ with example?
Is there any function that can skip certain number of characters present in the input stream?
Are c and c++ different?
what Is DCS ? what i will get benefit when i did?
Explain the term memory alignment?
What you know about structures in C++?