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 do we balance an AVL Tree in C++?
What is rtti in c++?
How many static variables are created if you put one static member into a template class definition?
True or false, if you keep incrementing a variable, it will become negative a) True b) False c) It depends
What is the limitation of cin while taking input for character array?
How the delete operator differs from the delete[]operator?
What is a class definition?
How many namespaces are there in c++?
Which ide is best for c++?
Explain about templates of C++.
What is scope resolution operator in c++ with example?
Differentiate between the manipulator and setf( ) function?
What is function prototyping? What are its advantages?
Describe about storage allocation and scope of global, extern, static, local and register variables?
What are inline functions? What is the syntax for defining an inline function?