-
Notifications
You must be signed in to change notification settings - Fork 0
/
Printing Unique array elements
58 lines (44 loc) · 1.09 KB
/
Printing Unique array elements
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
/*
Humza Khawar
Printing unique Elements
*/
#include<stdio.h>
void main()
{
//initializing the variables
int array1[50] = {0};
int unique_elements[50] = {0};
int num_unique_elements=0,num_of_elements1, repetition=0;
//taking input of arrays
printf("\nEnter Number Of Elements in first array : ");
scanf("%d", &num_of_elements1);
for (int i = 0; i < num_of_elements1; i++)
{
printf("\nEnter Number %d : ", i + 1);
scanf("%d", &array1[i]);
}
//calculating the repetition of every element in array
for (int i = 0; i < num_of_elements1; i++)
{
repetition = 0;
for (int j = 0; j < num_of_elements1; j++)
{
if ( array1[j] == array1[i] )
{
repetition++;
}
}
//if the element doenot repeat in the array then it is added to an array of unique element
if (repetition==1)
{
unique_elements[num_unique_elements] = array1[i];
num_unique_elements++;
}
}
//printing the elements
printf("\nThe unique numbers are \n ");
for(int i = 0; i <(num_unique_elements); i++)
{
printf("\t %d", unique_elements[i]);
}
}