Here's how I would do it in C#. It'll be a bit difficult to do it in C, especially since you don't have classes.
CODE
using System;
using System.Collections.Generic;
namespace Maxotek
{
static class Program
{
static void Main()
{
int[] userid_t = new int[] { 1001, 1002, 1003, 1001, 1001, 1002, 1004, 1005 };
char[] itemcode_t = new char[] { 'A', 'A', 'B', 'B', 'C', 'A', 'B', 'F' };
// Remove Duplicate Itemcodes
List<char> itemcodes = new List<char>();
for (int i = 0; i < itemcode_t.Length; i++)
if (!itemcodes.Contains(itemcode_t[i]))
itemcodes.Add(itemcode_t[i]);
// Sort Itemcodes
itemcodes.Sort();
List<int>[] frequency = new List<int>[itemcodes.Count];
for (int i = 0; i < userid_t.Length; i++)
{
int j = 0;
for (; j < itemcodes.Count; j++)
{
if (itemcodes[j] == itemcode_t[i])
break;
}
if (frequency[j] == null)
{
frequency[j] = new List<int>();
frequency[j].Add(userid_t[i]);
}
else if (!frequency[j].Contains(userid_t[i]))
frequency[j].Add(userid_t[i]);
}
// Display the result
for (int i = 0; i < itemcodes.Count; i++)
{
Console.WriteLine(itemcodes[i] + "-" + frequency[i].Count);
}
Console.Read();
}
}
}
With
List<int>[] frequency = new List<int>[itemcodes.Count];, I have declared an array of list of integers. It stores the userids that selected the itemcode at the corresponding index in the sorted itemcodes list. Before adding the userid to the list, we check if it has been already added and skip the step if it is. At the end we can obtain the distinct users by retrieving the count property of the each of the lists.
Comment/Reply (w/o sign-up)