my code

Hemton Anto

Largest and Smallest Number of an Array
by Hemton Anto

* This program contains an integer array & a float type variable cannot be stored in this array.
* Uses for loops to check for the largest and smallest elements of the array individually.

Snippet options

Download: Download snippet as largest-and-smallest-number-of-an-array.cpp.
Copy snippet: For this you need a free my code account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
    int n;
    cout << "\tFinding the Largest and Smallest Number of an Array : " << endl;
    cout << "\nEnter the number of Elements in your Array          : ";
    int* Arr1D = NULL;
    Arr1D = new int[n];
    cout << endl;
    for (int i=0; i<n; i++)
        cout<<"Enter the "<<i+1<<"st Element  : ";
        cin >> Arr1D[i];
    float Big = Arr1D[0], Small = Arr1D[0];
    for (int i=0; i<n; i++)
        if (Small < Arr1D[i])
            Small = Arr1D[i];
    for (int i=0; i<n; i++)
        if (Big > Arr1D[i])
            Big = Arr1D[i];
    cout << "\n\nThe Largest  Element is " << Big;
    cout << "\nThe Smallest Element is " << Small;
    delete [] Arr1D;
    Arr1D = NULL;
    return 0;

Create a free my code account now.

my code is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.