Answer to Question #292733 in C++ for Abdullah

Question #292733

Program to find smallest and largest number in array


1
Expert's answer
2022-02-01T11:59:05-0500
#include <iostream>


int find_smallest(int* arr, int size)
{
    int a = 10000;
    for (int i = 0; i != size; ++i)
    {
        if (arr[i] < a)
        {
            a = arr[i];
        }
    }
    return a;
}


int find_largest(int* arr, int size)
{
    int a = 0;
    for (int i = 0; i != size; ++i)
    {
        if (arr[i] > a)
        {
            a = arr[i];
        }
    }
    return a;
}




int main() {


    int arr[] = { 1, 50, 13, 89, 116 };
    std::cout << "Largest number: " << find_largest(arr, 5) << std::endl;
    std::cout << "Smallest number: " << find_smallest(arr, 5) << std::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