i have written the code as good as i can but it is failed is all cases
can any tell me the reason
Problem in question
#include
using namespace std;
int main() {
int r,n,n1,i,c,sum=0;
cin>>n;
for(i=0;i<n;i++)
{
cin>>n1;
while(n1>0)
{
r=n1%10;
n1=n1/10;
sum=sum+r;
}
if(sum%4==0)
cout<<“yes”;
else if(sum%4==0 && sum%3==0)
break;
else if(sum%3==0)
cout<<“yes”;
else
cout<<“no”;
cout<<endl;
}
return 0;
}
You logic is going wrong. Do a dry run and check it yourself.
What actually you are doing is that you are finding the sum of all digits and then checking its divisibility with 4 and 3 which is wrong. You have to find the sum of all digits which are even and the sum of all digits which are odd separately. If the sum of all even digits is divisible by 4 or sum of all odd digits is divisible by 3, then only print “Yes”. In all other cases print “No”.
i am such a dumb.
can u help me more in some other problems ?
If doubt is for the same question, then you can ask here.
For other question, post it as a separate doubt.
#include
using namespace std;
int main() {
int r,n,n1,i,eve=0,odd=0;
cin>>n;
for(i=0;i<n;i++)
{
odd=0;
eve=0;
cin>>n1;
while(n1>0)
{
r=n1%10;
n1=n1/10;
if(r%2==0)
eve=eve+r;
else
odd=odd+r;
}
if(eve%4==0)
cout<<“yes”<<“eve”;
else if(eve%4==0 && odd%3==0)
break;
else if(odd%3==0)
cout<<“yes”<<“odd”;
else
cout<<“no”;
cout<<endl;
}
return 0;
}
still getting wrong result
this is the result Submission Not Judged
and test cases passed
what does it mean ??
does it will remain like this forever ??
Check the pattern of output. Your output must match exactly with the sample output.
Sample Input
2
12345
12134
Sample Output
Yes
No
Condition must be something like this:
if(eve%4==0||odd%3==0)
cout<<Yes<<endl;
else
cout<<No<<endl;
answers are exact in code blocks IDE
my condion is
if(eve%4==0)
cout<<“yes”<;
else if(eve%4==0 && odd%3==0)
break;
else if(odd%3==0)
cout<<“yes”;
else
cout<<“no”;
You have to print “Yes” and “No” and not “yes” and “no”
check the conditional statements as i have said above.
If still problem continues, then save your code on ide.codingblocks.com and then share its link. I will make the corrections in your code.