-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLab_Ass3.C++
65 lines (64 loc) · 1.62 KB
/
Lab_Ass3.C++
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
/* 1. To print all unique elements
2.print no. of duplicate elements
3. Sum of all elements */
#include <iostream>
using namespace std;
int main()
{
int i, j, a[100], n, sum, count1, opt;
cout << "Enter number of elements in an array:" << endl;
cin >> n;
cout << "\nEnter " << n << " elements:" << endl;
for (i = 0; i < n; i++)
{
cin >> a[i];
}
cout << "Enter the task number associated with task you perform:\n1. Print unique elements\n2. Number of duplicate elements\n3. Sum of elements" << endl;
cin >> opt;
switch (opt)
{
case 1:
cout << "\nThe list of unique elements is:" << endl;
for (i = 0; i < n; i++)
{
count1 = 0;
for (j = 0; j < n; j++)
{
if (a[i] == a[j] && i != j)
{
count1++;
}
}
if (count1 == 0)
{
cout << a[i] << endl;
}
}
break;
case 2:
count1 = 0;
for (i = 0; i < n; i++)
{
for (j = i + 1; j < n; j++)
{
if (a[i] == a[j])
{
count1++;
break;
}
}
}
cout << "The number of repeating elements are:" << count1 << endl;
break;
case 3:
sum = 0;
for (i = 0; i < n; i++)
{
sum = sum + a[i];
}
cout << "\nThe sum of elements is: " << sum;
break;
default:
break;
}
}