-
Notifications
You must be signed in to change notification settings - Fork 0
/
oddValent.cpp
54 lines (47 loc) · 1015 Bytes
/
oddValent.cpp
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
#include <iostream>
using namespace std;
int findDuplicates(int array[]){
int counter = 1;
for(int i = 0; i <= sizeof(array) / sizeof(*array);i++){
for(int j = i+1; j <= sizeof(array)/sizeof(*array) ; j++){
if(array[i] == array[j]){
counter++;
}
cout << counter << endl;
}
}
if(counter > 1){
return 1;
}else{
return 0;
}
}
int findOdd(int array[]){
int counter = 0;
for(int i = 0; i < sizeof(array)/sizeof(*array); i++){
if(array[i] % 2 != 0){
counter++;
}
}
if(counter > 0){
return 1;
}else{
return 0;
}
}
int main(){
int length;
cout << "Please enter the size of the array : ";
cin >> length;
int array[length] = {};
for(int i = 0; i < sizeof(array)/sizeof(*array); i++){
cout << "Enter element "<< i << " : ";
cin >> array[i];
}
if(findDuplicates(array) == 1 && findOdd(array) == 1){
cout << "The array is Odd valent";
}else{
cout << "The array is not odd valent";
}
return 0;
}