Answer to Question #331789 in C++ for wdwqrrr

Question #331789

Write one dimensional array C++ program that ask to the user to enter the array size

and reads n integers, finds the largest of them, and count its occurrences. Suppose


1
Expert's answer
2022-04-21T07:02:56-0400
#include <iostream>
using namespace std;

int main() {
    int n = 0,  i, count=0;
    cout<<"Enter N: ";
    cin >> n;
    
    int *arr = new int[n];
    cout << "Enter " << n << " items" << endl;
    for (i = 0; i < n; i++) {
        cin >> *(arr+i);
    }
    
     cout << endl;
    int max = *arr;
     for (i = 1; i < n; i++) {
        if(*(arr+i) > max)
           max = *(arr+i);     
    }
     
    for (i = 0; i < n; i++) {
        if(*(arr+i) == max)
           count++;     
    }
    
 cout << "Largest:         "<<max<<endl;
 cout << "its occurrences: "<<count<<endl;
     
    delete [] arr;        
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS