Thursday, September 15, 2022

The Largest Number in an Array in C++

 A program asks the user to give seven numbers and then the program will check and determine which of the seven numbers given is the largest number and its location in a one-dimensional array using a C++ programming language.

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.

Please subscribe to my channel  https://www.youtube.com/channel/UCOs-lpOoIeJoh6gpJthPoGg

=================================================


Want to support my channel?

GCash Account

Jake Pomperada


09173084360


Paypal

https://paypal.me/jakerpomperada


Patreon

https://www.patreon.com/jakerpomperada


Thank you very much for your support.




Program Listing

/* largest.cpp
   Author : Jake Rodriguez Pomperada, MAED-IT, MIT
   www.jakerpomperada.com  and www.jakerpomperada.blogspot.com
   jakerpomperada@gmail.com
   Bacolod City, Negros Occidental
   September 15, 2022  Thursday  6:54 PM
*/


#include <iostream>

using namespace std;

int main() {

  int i=0, n=0;
  int arr[7];
  int b = sizeof(arr)/sizeof(arr[0]);
  int y=0;  int index=0;
 
  cout <<"\n\n";
  cout << "\tThe Largest Number in an Array in C++";
  cout <<"\n\n";
  
  for(i = 0; i < 7; ++i) {
    cout << "\tEnter Number " << i + 1 << " : ";
    cin >> arr[i];
  }
 cout <<"\n\n";
 cout << "\tList of Array Elements\n\n";
 
   for(i = 0;i <7; ++i) {

     cout << "\tElement Value [" << i+1 << "] = " 
<<arr[i] <<"\n";
  }
  for(i = 1;i < 7; ++i) {


    if(arr[0] < arr[i])
      arr[0] = arr[i];
  }

  cout << endl << "\tLargest element = " << arr[0];
  cout << "\n\n";
  for(y=1; y<7; y++)
    {
        if(arr[y]==arr[0])
        {
            index = y+1;
            break;
        }
    }
    cout <<"\n";
     cout<<"\n\tThe Largest Number " <<arr[0] <<
" at Location Number "<<index <<".";
  return 0;
}

No comments:

Post a Comment