Originally Posted by
laserlight
Instead of guessing, why don't you go through the algorithm with unsorted input and see what you get, and then implement it and try it for an unsorted array to confirm?
I have set one counter to count repeated number but it's not work as I want
Code:
#include <stdio.h> int main()
{
int list [5] = {1, 2, 1, 2, 4};
int i = 0; int j = 0; int counter = 0;
for (i=0; i<5; i++)
{
for ( j = i + 1; j < 5; j++)
{
if (list[i] == list[j])
{
printf(" Number %d is repeated in list \n", list[i]);
counter++;
}
}
}
printf(" %d \n", counter);
counter = 0;
return 0;
}
Number 1 is repeated in list
1
Number 2 is repeated in list
2
2
2
2