Math, asked by AnshumanPani1922, 1 year ago

To find second largest number among the 5 numbers given.


Prashant24IITBHU: where r the numbers?

Answers

Answered by krishnasweethap8nkwf
1
finding 2nd largest number from 5 given numbers Mar 31, 2012 at 9:09pmhari2897 (2)write a C++ program to find the 2nd largest no. from given 5 numbersLast edited on Mar 31, 2012 at 9:09pm Mar 31, 2012 at 9:15pmfrema (38)Sort and pick the second. Mar 31, 2012 at 9:17pmhari2897 (2)can you please write the program which finds the 2nd largest number from given 5 numbers
Last edited on Mar 31, 2012 at 9:18pm Mar 31, 2012 at 9:35pmFactors (90)Most People wont just hand you code for the hell of it. So ill give you a start.


First you have to select a library that you want to transfer in to your .cpp or program file.

#include <[library name]> 

Then after that you have the option of using namespaces or function's or w.e you want.

using namespace [insert namespace];

After that you have to get down to the program, so to tell your c++ compiler to start at a certain point you use a function by the name of main.

1
2
3
4
5
[insert type] main ([insert w.e]) { } Edit & Run


Now inside the curly brackets you will have to write what you want c++ to do/ launch/ accomplish.

Most commonly sense you wish to deal with number's, it is recommended to create a variable with a type specifying to you number's type.
int, long, double,or float(sense you wish to use 5 different number you need 5 different variable or a array with 5 element's. But to keep it simple i would recommend the use of a array with 5 element's);

1
2
3
4
5
[insert type] main ([insert w.e]) { float [insert Array][elements] ; } Edit & Run


Now that you have a array with five element's(no value has been given to them yet so they are called unsigned) we can manipulate them how ever we want.

Post what you think would be required to accomplish what your asking for.

1
2
3
4
5
6
7
8
[insert type] main ([insert w.e]) { float [insert Array][elements] ; blah blah blah blah blah blah blah blah blah blah blah blah } Edit & Run
 Mar 31, 2012 at 9:49pmvlad from moscow (6539)I can suggest the following algorithm


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream> int main() { int a, b, c, d, e; std::cout << "Enter 5 integer numbers: "; std::cin >> a >> b >> c >> d >> e; int max1, max2; if ( a < b ) max1 = b, max2 = a; else max1 = a, max2 = b; if ( max1 < c ) max2 = max1, max1 = c; else if ( max2 < c ) max2 = c; if ( max1 < d ) max2 = max1, max1 = d; else if ( max2 < d ) max2 = d; if ( max1 < e ) max2 = max1, max1 = e; else if ( max2 < e ) max2 = e; std::cout << "The second maximum value = " << max2 << std::endl; return ( 0 ); } Edit & Run

Answered by jaswantsardar4
0

Answer:

WAP to find the second largest number among 5 different numbers.

Similar questions