I am having trouble with this programming question I am getting several errors.
ID: 3544413 • Letter: I
Question
I am having trouble with this programming question I am getting several errors. Can someone help me with this, if someone could code it up an I could see where I went wrong
Write a program that reads in an array of type int . You may assume that there
are fewer than 50 entries in the array. Your program determines how many entries
are used. 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 the array values
Explanation / Answer
This is a C++ code as per your requirement.
#include<conio.h>
#include<stdio.h>
int main()
{
int a[50],i,j,n,c=0,temp,b[50];
printf(" Enter the number of terms : ");
scanf("%d",&n);
printf(" Enter the terms : ");
for(i=0;i<n;i++) //input array
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++) //sorting array
{
for(j=0;j<n;j++)
{
if(a[j+1]<a[j])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
printf("The output is : N Count ");
for(i=0;i<n;i++)
{
c=0;
b[i]=a[i-1];
for(j=i;j<n;j++)
{
if(a[i]==b[i])
continue;
else if(a[i]==a[j])
c+=1;
}
if(a[i]!=b[i]) //printing only unique values of N
printf("%d %d ",a[i],c);
}
getch();
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.