Monday, March 1, 2021

Smallest and Biggest Element in an Array in C++

 I wrote this program to ask the user to give a series of elements in an array and then it will check what element has the smallest and biggest numerical values using C++ programming languages.

I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me at the following email address for further details.  If you want to advertise on my website kindly contact me also in my email address also. Thank you.

My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.




Program Listing


// arrays.cpp

// Jake R. Pomperada, MAED-IT,MIT

// www.jakerpomperada.com

// www.jakerpomperada.blogspot.com

// jakerpomperada@gmail.com

// Bacolod City, Negros Occidental



#include<iostream>


int main ()

{

    int arr[20];

int n=0, i=0, max=0, min=0;

    std::cout <<"\n\n";

    std::cout <<"\tSmallest and Biggest Element in an Array in C++";

    std::cout <<"\n\n";

    std::cout << "\tGive the size of the array : ";

    std::cin >> n;

    std::cout <<"\n\n";

     for (i = 0; i < n; i++) {

   std::cout << "\tGive value in element no. " << i+1 << " : ";

       std::cin >> arr[i];

       }

    max = arr[0];

    for (i = 0; i < n; i++)

    {

        if (max < arr[i])

            max = arr[i];

    }

    min = arr[0];

    for (i = 0; i < n; i++)

    {

        if (min > arr[i])

            min = arr[i];

    }

    std::cout <<"\n\n";

    std::cout << "\tThe Biggest  Element : " << max;

    std::cout <<"\n\n";

    std::cout << "\tThe Smallest Element : " << min;

    std::cout <<"\n\n";

    std::cout <<"\tEnd of Program";

  }

No comments:

Post a Comment