Delhi odd even problem

#include
using namespace std;
int main() {
int t,n;
cin>>t;
int rem,sum;
while(t>0){
cin>>n;
rem=0;
sum=0;
while(n>0){
rem=n%10;
sum=sum+rem;
n=n/10;
}
if(sum%2==0)
{
if(sum%4==0)
{
cout<<β€œYes”<<endl;
}
else
{
cout<<β€œNo”<<endl;
}
}
else
{
if(sum%3==0)
{
cout<<β€œYes”<<endl;
}
else
{
cout<<β€œNo”<<endl;
}
}
t=t-1;
}
return 0;
}

output is correct still the test case is not passed?

Hi @chaman9
u should read the question again

each car will be allowed to run on Sunday if the sum of digits which are even is divisible by 4 or sum of digits which are odd in that number is divisible by 3.

so, u need to sum up odd_sum & even_sum for the given digit ,
then check if even sum is divisible by 4
or if odd sum is divisible by 3
then o/p yes
else no

1 Like

Thanks a lot… i got the solution

Can you please tell me what is wrong with this code
#include

using namespace std;

int main()

{

int k,o=0,e=0,n,no,i,p,q;

cin>>p;

if(p>=0 && p<=1000)

{n=p;}

for(i=0;i<n;i++)

{cin>>q;

if(q<=1000000000 && q>=0)

{no=q;}

while(no!=0)

{

k=(no%10);

no=no/10;

if(k%2==0)

{e=e+k;}

else{o=o+k;}

}

if(e%4==0 || o%3==0)

{cout<<β€œYES”;}

else{cout<<β€œNO”;

}

e=0;

o=0;

cout<<"\n";}

return 0;

}

share code in cb ide

1 Like

how to share code in cb ide

open https://ide.codingblocks.com/
put ur code there
in the files option click save
url gets updated share that url here

1 Like

I have completed the delhi odd even question but got stuck in this question only one test case got passed can you please tell me what is wrong in this code?

Write a program that works as a simple calculator.

1.It reads a character (ch)
2.If ch is among β€˜+’, β€˜-’, β€˜*’, β€˜/’ or β€˜%’ it furthur takes two numbers (N1 and N2 as input). It then performs appropriate appropriate operation between numbers and print the number.
3.If ch is β€˜X’ or β€˜x’, the program terminates.
4.If ch is any other character, the program should print β€˜Invalid operation. Try again.’ and seek inputs again (starting from character).

Write code to achieve above functionality.

Input Format

Constraints

0 <= Input integers <= 100000000
( It is assured that the second integer provided for division and modulo operations will not be 0. )

while condition needs to be updated
and cin >> ch after each computation

1 Like