Skip to content

Commit

Permalink
Merge pull request #232 from EmanKhaliq49/main
Browse files Browse the repository at this point in the history
Create POTD_31_OCT_2024_Largestnumber_in_an_array.cpp
  • Loading branch information
Gyanthakur authored Oct 31, 2024
2 parents f72f184 + bda62ae commit 56caddf
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions POTD_31_OCT_2024_Largestnumber_in_an_array.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <iostream>

using namespace std;
void largestnumber(int data, int arr[], int &loc, int &max)
{

loc = 1;
max = arr[1];
for(int k=1;k<data;k++){
if(max<arr[k]){
max = arr[k];
loc=k;
}

}
}

int main(){
int data;


cout<<"How many numbers you want to add in a array?"<<endl;
cin>>data;

int arr[data];
cout<<"Enter the numbers to be stored in array: "<<endl;
for(int i=0; i<data; i++){
cin>>arr[i];
}

int loc;
int max;
largestnumber(data, arr, loc, max);
cout << "The largest element is " << max << " at position " << loc << "\n";

return 0;
}

0 comments on commit 56caddf

Please sign in to comment.