Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please explain every step in this code. #include #include using namespace std; int main() { int n = 0, count, arr[50], i = 0, j,

Please explain every step in this code.

#include #include using namespace std;

int main() { int n = 0, count, arr[50], i = 0, j, input; char x[50]; cout << "Enter 1 for user input and other number for file input: "; cin >> input; if(input == 1){ cout << " How many numbers? "; cin >> n; cout << "Enter " << n << " integers: "; for(i = 0; i < n; i++) cin >> arr[i]; } if(input != 1){ cout << " Enter a file name with directory: "; cin >> x; ifstream myFile(x); while(myFile >> arr[i]){ n++; i++; } } for(i = 0; i < n; i++){ for(j = 0; j <= i; j++){ if(arr[i] > arr[j]){ int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } } } cout << " N\tCount "; for(i = 0; i < n; i++){ count = 1; while(arr[i] == arr[i + 1] && i < n){ count++; i++; } cout << arr[i] << "\t" << count << endl; } return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

9th Edition

0135188148, 978-0135188149, 9781642087611

More Books

Students also viewed these Databases questions

Question

differentiate the function ( x + 1 ) / ( x ^ 3 + x - 6 )

Answered: 1 week ago

Question

3. Would you say that effective teamwork saved their lives?

Answered: 1 week ago