the question is absolutely correct.
In your approach when a-b is 1 it will print 0 as answer and in constraints it is clearly written that answer should be a positive number.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
printf(“enter the value of a and b:”);
scanf("%d%d",&a,&b);
if((a-b)%10==9)
if(a-b==1)
break;
printf(\n a-b-1);
else
printf(\n a-b+1);
getch();
}
/* I don’t understand what is wrong with this code? */
#include<stdio.h>
int main()
{
int a,b;
scanf("%d %d",&a,&b);
int temp = a-b;
temp = temp/10;
int result = 0;
int power = 10;
int k;
while(temp)
{
k = temp%10;
result = result + kpower;
temp = temp/10;
power = power10;
}
printf("%d\n",result);
return 0;
}
gave answer on the question…
For example consider the two numbers to be 1020 and 20
the difference will give you 1000
printing 1000 will be wrong
printing less than 1000 is wrong (no of digits is getting reduced)
0100 0010 0001 are wrong answers, because they have 0 infront of them.
So, what should be the answer in this case ?
#python script, one liner:
a,b=(int(x) for x in input().split(’ '));print(a-b+1 if (a-b)%10<9 else a-b-1)