Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!