Hi, I'm pretty new to programming and I'm having some trouble with this. I need to create a program that counts the amount of different numbers in an array, for example if the user entered the numbers: 858443 the result would be:
8 occurs 2 times
5 occurs 1 time
4 occurs 2 times
3 occurs 1 time
I can get the prgram to ask the user to enter the amount of numbers they're going to enter and I can get those numbers and store them in the array but then I'm not sure what to do. They also need to be in descending order, heres what I have so far:
Code:
#include <stdio.h>
#define NUMBERS 10
int main ()
{
int count[NUMBERS];
int i = 0, num_st, input_ok = 0, total = 0;
/* initialise the array */
for (i = 0; i < NUMBERS; i++)
count[i] = 0;
/* get the amount of numbers */
printf("Enter the amount of numbers > ");
do
{
scanf("%d", &num_st);
if (num_st >=0 && num_st <= 10)
input_ok = 1;
else
printf("Error> Max number is %d, Try again \n", NUMBERS);
}
while (input_ok == 0);
/* get values */
for (i = 0; i < num_st; i++){
printf("Enter #%d > ", i+1);
scanf("%d", &count[i]);
total = total + count[i];
}
}
Any help would be greatly appreciated