Computer Science, asked by jaydhote099, 2 months ago

write a algorithm to find the smallest and largest number using arrays​

Answers

Answered by guparchana19
0

Answer:

lgorithm to find the smallest and largest numbers in an array

Input the array elements.

Initialize small = large = arr[0]

Repeat from i = 2 to n.

if(arr[i] > large)

large = arr[i]

if(arr[i] < small)

small = arr[i]

Print small and large.

Explanation:

Answered by WildCat7083
20

// C++ program to find maximum in arr[] of size n

#include <bits/stdc++.h>

using namespace std;

// returns maximum in arr[] of size n

int largest(int arr[], int n)

{

    return *max_element(arr, arr+n);

}

int main()

{

    int arr[ ] = {10, 324, 100,6382,71891929};

    int n = sizeof(arr)/sizeof(arr[0]);

    cout << largest(arr, n);

    return 0;

}

Output:

71891929

 \sf \: @WildCat7083

Similar questions