Answer to Question #3320 in C++ for mukunda

Question #3320
Write a program to find the biggest and smallest numbers in the array?
1
Expert's answer
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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS