 # DIGSMPA this is the question code.

and this is my approach , my output is wright but it is showing wrong.

``````#include <iostream>
using namespace std;

int next_digitsum(int n,int res)
{
int sum = 0, temp = n,r;
while (temp != 0)
{ // int temp1=n;
sum += temp % 10;
temp = temp / 10;
}
if(sum%2==0)
r=1;
else
r=0;
if(r!=res)
return n;
else
return next_digitsum(n+1,r);

}

int main()
{
int t, num,sum=0;
cin >> t;
for (int i = 0; i < t; i++)
{
cin >> num;
int temp=num;
while(num!=0)
{
sum+=num%10;
num=num/10;
}
if(sum%2==0)
cout<< next_digitsum(temp+1,1)<<endl;
else
cout<<next_digitsum(temp+1,0);
}
return 0;
}
``````

please give a proper formatted code with problem statement

Hey, could you add the question link for which you have written the solution? Also, to get a faster response, you should try and write down your logic along with the implementation, which makes it is easier for users to understand your approach and find possible flaws in it.

Hey, there are 2 mistakes in your code

1. You have not printed an endline after the print statement in the else block.
2. You need to reset the value of cnt to 0 for every testcase.

I have made some changes in your code and it passed, please go through it to understand:

``````#include <iostream>
using namespace std;

int next_digitsum(int n,int res)
{
int sum = 0, temp = n,r;
while (temp != 0)
{ // int temp1=n;
sum += temp % 10;
temp = temp / 10;
}
if(sum%2==0)
r=1;
else
r=0;
if(r!=res)
return n;
else
return next_digitsum(n+1,r);

}

int main()
{
int t, num,sum=0;
cin >> t;
for (int i = 0; i < t; i++)
{
sum = 0;
cin >> num;
int temp=num;
while(num!=0)
{
sum+=num%10;
num=num/10;
}
if(sum%2==0)
cout<< next_digitsum(temp+1,1)<<endl;
else
cout<<next_digitsum(temp+1,0) << endl;
}
return 0;
}
``````