1112. Number Steps Problem code: NSTEPS
#include<stdio.h>
int main()
{
int n , i , x, y;
scanf("%d", &n);
for (i = 0 ; i< n ;i++)
{
scanf("%d", &x);
scanf("%d" , &y);
if (x%2==0 && y%2==0 && (x-y ==2 || x-y == 0 ))
printf("%d\n" , x+y);
else if ((x+1)%2==0 && (y+1)%2==0 && (x-y ==2 || x-y == 0 ))
printf("%d\n" , x+y-1);
else
printf("No Number\n");
}
return 0;
}
#include<stdio.h>
int main()
{
int n , i , x, y;
scanf("%d", &n);
for (i = 0 ; i< n ;i++)
{
scanf("%d", &x);
scanf("%d" , &y);
if (x%2==0 && y%2==0 && (x-y ==2 || x-y == 0 ))
printf("%d\n" , x+y);
else if ((x+1)%2==0 && (y+1)%2==0 && (x-y ==2 || x-y == 0 ))
printf("%d\n" , x+y-1);
else
printf("No Number\n");
}
return 0;
}
#include
ReplyDeleteint main()
{
int n , i , x, y;
scanf("%d", &n);
for (i = 0 ; i< n ;i++)
{
scanf("%d", &x);
scanf("%d" , &y);
if (x%2==0 && y%2==0 && (x-y ==2 || x-y == 0 ))
printf("%d\n" , x+y);
else if ((x+1)%2==0 && (y+1)%2==0 && (x-y ==2 || x-y == 0 ))
printf("%d\n" , x+y-1);
else
printf("No Number\n");
}
return 0;
}
Tell me why this code is not working.Thanks in advance
#include
ReplyDeleteint main()
{
int t,a,b,i,s;
scanf("%d",&t);
for(i=1;i<=t;i++)
{
scanf("%d%d",&a,&b);
s=a+b;
if(s%2!=0)
printf("No Number\n");
else
{
if((a==0||b==0)&&(s!=0&&a!=2))
printf("No Number\n");
else if(a%2==0)
printf("%d\n",s);
else
printf("%d\n",s-1);
}
}
return 0;
}
Sorry for the previous comment....This s my code actually...Y is this not working???
Thanks in advance
Note the following:
Delete1) either both x and y should be even or they should be odd
2) x and y can differ from each other by either 0 or 2.
if both the above conditions are satisfied, then the answer will be x+y if x and y are even else answer will be x+y-1
if above conditions are not satisfied: "No Number"
#include
ReplyDelete#include
#include
using namespace std;
int main()
{
int x,y,t,a;
cin>>t;
while(t--)
{
cin>>x;
cin>>y;
if(x==y || y==x-2)
{
if(x%2)
{
a=x+y-1;
}
else
a=x+y;
cout<<a<<endl;
}
else
cout<<"No Number\n";
}
return 0;
}