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
Which sort does c++ use?
What is iomanip c++?
What does the ios::ate argument do?
Is c++ faster than c?
What is null pointer and void pointer and what is their use?
Explain how would you handle a situation where you cannot call the destructor of a local explicitly?
What is singleton class in c++?
How many namespaces are there in c++?
Write a Program for find and replace a character in a string.
Which programming language should I learn first?
What is a try block?
How is c++ different from java?
What is the basic concept of c++?
What is type of 'this' pointer?
Explain how to initialize a const data member.