Untitled
unknown
plain_text
a year ago
688 B
6
Indexable
#include <iostream> using namespace std; int main() { int arr[100], n, i; cout << "Enter the size of the array: "; cin >> n; cout << "Enter the elements of the array: "; for (i = 0; i < n; i++) { cin >> arr[i]; } int largest = arr[0]; int smallest = arr[0]; // Find the largest element for (i = 1; i < n; i++) { if (arr[i] > largest) { largest = arr[i]; } } // Find the smallest element for (i = 1; i < n; i++) { if (arr[i] < smallest) { smallest = arr[i]; } } cout << "Largest element: " << largest << endl; cout << "Smallest element: " << smallest << endl; return 0; }
Editor is loading...
Leave a Comment