Help me for duplicate random number.

Hi, I am new here and Im looking for some help. I am trying to make my array without any duplicate number.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define BUBBLE 5
int main()
{
	int myArray[BUBBLE];
	int i, j ,a , b, k;
	int temp = 0;
	int num;
	int cunt;
	cunt=0;
    float floatType;
    int integerType;
    


	srand(time(NULL));
    
	//Fill Array Randomlly
	for (i = 0; i < BUBBLE; i ++)
	{    
		   num = rand() % BUBBLE + 1;
		   myArray[i] = num;
	}
	
// For remove duplicate number
for (a = 0; i < BUBBLE; a++) {
      for (b = a + 1; j < BUBBLE;) {
         if (myArray[a] == myArray[b]) {
            for (k = b; k < BUBBLE; k++) {
                myArray[k] =  myArray[k + 1];
            }
            BUBBLE--;
         } else
            b++;
      }
   }


	// The Array Before Sort
	for (i = 0; i < BUBBLE; i++)
	{
		printf("%d \n ",myArray[i]);
	
	}
	
   		printf("After sort \n",myArray[i]);

	
	//Sort Array With Bobble Algorhim
	for(i = 0; i < BUBBLE; i++)
	{

		for (j = 0; j < BUBBLE-1; j++)
        {
            if (myArray[j] > myArray[j+1])
			{
				temp = myArray[j];
				myArray[j] = myArray[j+1];
				myArray[j+1] = temp;
				
				cunt++;
			}
        }
	}
  
	
	//Print Array After Sort
	for (i = 0; i < BUBBLE; i++)
	{
		printf("%d\n",myArray[i]);
	
	}
	// Count For How Many Swap
		 printf("the numbeer of pases is %d \n" ,cunt);
		  printf("Size of float: %ld bytes\n",sizeof(floatType));
	system("PAUSE");	
	return 0;
}



Last edited on
I don't see a question.
To respond to your statement "I am trying to make my array without any duplicate number. "
My suggestion would be simply add "count" to every number and then increase "count" by one. Done.
Registered users can post here. Sign in or register to post.