-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDigit_sum_parity.cpp
60 lines (60 loc) · 1.18 KB
/
Digit_sum_parity.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
55
56
57
58
59
60
#include <iostream>
using namespace std;
int digitsum(long a){
int s=0;
while(a!=0){
int x=a%10;
s=s+x;
a=a/10;
}
return s;
}
long evenparity(long a){ //Or method using function by calling the functions
while(1){
a++;
int i=digitsum(a);
if((i%2)!=0){
return a;
break;
}
}
}
long oddparity(long a){ //Or method using function by calling the fucntions
while(1){
a++;
int i=digitsum(a);
if((i%2)==0){
return a;
break;
}
}
}
int main() {
// your code goes here
int t;
cin>>t;
while(t--){
long n;
long x;
cin>>n;
int m=digitsum(n);
while(1){
n++;
if(m%2==0){
int i=digitsum(n);
if((i%2)!=0){
cout<<n<<endl;
break;
}
}
else{
int i=digitsum(n);
if(i%2==0){
cout<<n<<endl;
break;
}
}
}
}
return 0;
}