File tree Expand file tree Collapse file tree 1 file changed +58
-0
lines changed Expand file tree Collapse file tree 1 file changed +58
-0
lines changed Original file line number Diff line number Diff line change
1
+
2
+
3
+ /*
4
+ Humza Khawar
5
+ Printing unique Elements
6
+
7
+ */
8
+ #include<stdio.h>
9
+
10
+ void main()
11
+ {
12
+ //initializing the variables
13
+ int array1[50] = {0};
14
+ int unique_elements[50] = {0};
15
+ int num_unique_elements=0,num_of_elements1, repetition=0;
16
+
17
+
18
+ //taking input of arrays
19
+ printf("\nEnter Number Of Elements in first array : ");
20
+ scanf("%d", &num_of_elements1);
21
+
22
+ for (int i = 0; i < num_of_elements1; i++)
23
+ {
24
+ printf("\nEnter Number %d : ", i + 1);
25
+ scanf("%d", &array1[i]);
26
+ }
27
+ //calculating the repetition of every element in array
28
+ for (int i = 0; i < num_of_elements1; i++)
29
+ {
30
+ repetition = 0;
31
+
32
+ for (int j = 0; j < num_of_elements1; j++)
33
+ {
34
+ if ( array1[j] == array1[i] )
35
+ {
36
+ repetition++;
37
+ }
38
+ }
39
+ //if the element doenot repeat in the array then it is added to an array of unique element
40
+ if (repetition==1)
41
+ {
42
+ unique_elements[num_unique_elements] = array1[i];
43
+ num_unique_elements++;
44
+
45
+ }
46
+ }
47
+
48
+
49
+ //printing the elements
50
+ printf("\nThe unique numbers are \n ");
51
+
52
+ for(int i = 0; i <(num_unique_elements); i++)
53
+ {
54
+ printf("\t %d", unique_elements[i]);
55
+
56
+ }
57
+
58
+ }
You can’t perform that action at this time.
0 commit comments