#include<stdio.h>
int main(){
int i,j,k;
scanf("%d%d",&i,&j);
k = i-j;
if(k%10!=9) k++; else k–;
printf("%d\n",k);
return 0;
}
why we are using mod 10 !=9
can some one explain
#include<stdio.h>
int main(){
int i,j,k;
scanf("%d%d",&i,&j);
k = i-j;
if(k%10!=9) k++; else k–;
printf("%d\n",k);
return 0;
}
why we are using mod 10 !=9
can some one explain
it is for the case our value is not equal to 9, in that case we increment it by 1…otherwise we decrease by 1.
that i understand but why we are applying that condition cannt we simply write
#include
using namespace std;
int main() {
int a,b;
cin>>a;
cin>>b;
int c=(a-b)+1;
cout<<c;
}
Think it in this way,
Let us suppose for our example, a = 875, b = 466
Thus, a - b = 875 - 466
= 409
Thus, a - b + 1 = 410
But, 2 digits are misplaced here, the tens digit should have been 0, and its 1. And the ones digit should have been 9 but it is 0.
Thus, you would get a WA. To avoid this conversion, the code have the statement:
if(k%10 !=9)