You are on page 1of 1

18. Write a C++ program that requests five integer values from the user.

It then prints the maximum


and minimum values entered. If the user enters the values 3, 2, 5, 0, and 1, the program would
indicate that5isthemaximumand0istheminimum. Your program should handle ties properly; for
example, if the user enters 2, 4, 2, 3, and 3, the program should report 2 as the minimum and 4 as
maximum.

Ans.
#include <iostream>
using namespace std;
int main()
{
int mn, mx;
const int Numb = 10;
int a[Numb]; //10 elements
cout << "Enter 10 values:"; //prompts user for 10 values.
for (int i = 0; i<10; i++)
{
cout << "\nEnter value: ";
cin >> a[i]; // puts values in array
}

mn = a[0];
mx = a[0];
for (int i = 1; i<10; i++)
{
if (mn>a[i])
{
mn = a[i];
}
else if (mx<a[i])
{
mx = a[i];
}
}

cout << "Maximum number is: " << mx << endl;


cout << "Minimum number is: " << mn << endl;

int i;
cin >> i;
return 0;

19. Write a C++ program that requests five integer values from the user. It then prints one of two
things: if any of the values entered are duplicates, it prints "DUPLICATES"; otherwise, it prints "ALL
UNIQUE".

You might also like