Answer to Question #3320 in C++ for mukunda
Write a program to find the biggest and smallest numbers in the array?
1
2011-07-11T09:56:10-0400
#include <iostream>
using namespace std;
int main()
{
const int N = 5;
int arr[N] = { 10, 46, -37, 8, 19 };
int smallest = 0, biggest = 0;
for (int i = 1; i < N; ++i) {
if (arr[smallest] > arr[i])
smallest = i;
if (arr[biggest] < arr[i])
biggest = i;
}
cout << "The smallest number in the array is " << arr[smallest] << endl;
cout << "The biggest number in the array is " << arr[biggest] << endl;
return 0;
}
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Learn more about our help with Assignments:
C++
Comments
Leave a comment