Please help me with the following program in C++ Write a program that reads in a
ID: 3547554 • Letter: P
Question
Please help me with the following program in C++
Write a program that reads in a list of integers into an array with base type int. Provide the facility to either read this array from the keyboard or from a file, at the user's option. If the user chooses file input, the program should request a file name. You may assume that there are fewer than 50 entries in the array. Your program determines how many entries there are. The output is to be a two-column list. The first column is a list of the distinct array elements; the second column is the count of the number of occurrences of each element. The list should be sorted on entries in the first column, largest to smallest. For example, for the input -12 3 -12 4 1 1 -12 1 -1 1 2 3 4 2 3 -12 the output should beExplanation / Answer
This would help you for any input size.
#include<stdio.h>
#include<conio.h>
int main()
{
int n,i,temp,count=0,j=0,flag=0;
printf("Enter the number of elements ");
scanf("%d",&n);
int input[n],output[n];
printf("Enter the elements of array ");
for(i=0;i<n;i++)
scanf("%d",&input[i]);
while(j!=n)
{
temp=input[j];
count=0;
for(i=0;i<n;i++)
{
if(temp==input[i])
count++;
}
output[j]=count;
j++;
}
printf(" N Count ");
for(i=0;i<n;i++)
{
flag=0;
for(j=i-1;j>-1;j--)
{
if(input[i]==input[j])
flag++;
}
if(flag==0)
printf("%d %d ",input[i],output[i]);
}
getch();
return 0;
}