Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create POTD_31_OCT_2024_Largestnumber_in_an_array.cpp #232

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
Loading
Oops, something went wrong.