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
Can we use pointers in c++?
If horse and bird inherit virtual public from animal, do their constructors initialize the animal constructor? If pegasus inherits from both horse and bird, how does it initialize animal’s constructor?
What does the ios::ate argument do?
Define pointers?
Which programming language's unsatisfactory performance led to the discovery of c++?
How many ways can a variable be initialized into in C++?
Are there any special rules about inlining?
What is the use of endl?
What are proxy objects in c++?
Will rust take over c++?
What are the sizes and ranges of the basic c++ data types?
What is c++ runtime?
how can i access a direct (absolute, not the offset) memory
address?
here is what i tried:
wrote a program that ask's for an address from the user,
creates a FAR pointer to that adress and shows it. then the
user can increment/decrement the value in that address by
pressing p(inc+) and m(dec-).
NOW, i compiled that program and opened it twice (in 2
different windows) and gave twice the same address to it.
now look what happen - if i change the value in
one "window" of the program, it DOES NOT change in the
other! even if they point to the same address in the memory!
here is the code snippet:
//------------------------------------------------------
#include What is class syntax c++? What are the restrictions apply to constructors and destructors?