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
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started