#include<iostream>
using namespace std;
int main()
{
int n1,n2,n3,n4,n5;
cout<<"input number1\n";
cin>>n1;
cout<<"input number2\n";
cin>>n2;
cout<<"input number3\n";
cin>>n3;
cout<<"input number4\n";
cin>>n4;
cout<<"input number5\n";
cin>>n5;

if(n1 < n2)
n1 = n2;
if(n1 < n3)
n1 = n3;
if(n1 < n4)
n1=n4;
if (n1<n5)
n1=n5;

cout << "The largest number is\n" << n1 <<endl;

return 0;
} (im a student plz help me with modification)

What seems to be the problem with it? It looks as if it should do what you want, but we need to know what problem you are having in order to help solve it.

Also, please put your code examples in CODE tags in the future. The forum software does not retain indentation by default, so without the code tags, you lose the code's formatting, making it difficult to read clearly.

in this code i can get only the largest value tel me how to find smallest value also frnd anywy tnx 4 ur rply

Since you need both a largest value and a smallest value, you will want to declare two variables to hold the two results. Assign the value of `n1` to both of them, then substitute ' `largest` ' for the `n1` in your comparisons. This will get you the largest value, just as it did before. Now do the same with the ' `smallest` ' variable, just reversing the comparison (that is, use greater than rather than less than).

``````#include<iostream>
using namespace std;

int main()
{
int n1,n2,n3,n4,n5;
int largest, smallest;

cout << "input number1\n";
cin  >> n1;
cout << "input number2\n";
cin  >> n2;
cout << "input number3\n";
cin  >> n3;
cout << "input number4\n";
cin  >> n4;
cout << "input number5\n";
cin  >> n5;

largest = smallest = n1;

if(largest < n2)
largest = n2;
if(largest < n3)
largest = n3;
if(largest < n4)
largest = n4;
if(largest < n5)
largest = n5;

// TODO: the same thing as above, except replacing
// 'largest' with 'smallest' and '<' with '>'

cout << "The largest number is" << largest <<endl;
cout << "The smallest number is" << smallest <<endl;

return 0;
}``````

If you have studied arrays, there is a good way to simplify the code using an array instead of having separate variables named `n1` , `n2` , `n3` , etc. Experiment with it a little, and you should find something useful.

As a final note, I have to ask you to write out full words rather than using SMS-type abbreviations. Most of the people here won't reply to a message written in text-speak.

``````#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef std::vector<int>vInts;

int main()
{
vInts v;
int user_input;
for( int i = 0; i < 5; i++ )
{
cout << "Enter a number: ";
cin >> user_input;
v.push_back( user_input );
}
sort( v.begin(), v.end() );
cout << "The largest number you entered is: " << v[-1 + v.size()] << endl;

return 0;
}``````

thank you very much for supporting me

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.