Time spent here:

Thursday, 24 December 2015

DIFFERENCE TRICK

In Manish's restaurant, a waiter is training. Since the waiter isn't good at arithmetic, sometimes he gives guests wrong change. Manish gives him a simple problem. What is A-B (A minus B) ?
Surprisingly, his answer is wrong. To be more precise, his answer has exactly one wrong digit. Can you imagine this? Can you make the same mistake in this problem?
INPUT
An input contains 2 integers A and B.
OUTPUT
Print a wrong answer of A-B. Your answer must be a positive integer containing the same number of digits as the correct answer, and exactly one digit must differ from the correct answer. Leading zeros are not allowed. If there are multiple answers satisfying the above conditions, anyone will do.
CONSTRAINTS
1B < A10000

Sample Input
(Plaintext Link)
5858 1234
Sample Output
(Plaintext Link)
1624
 

SOLUTION:

#include<stdio.h>
int main()
{
    int a,b,diff;
    scanf("%d%d",&a,&b);
    diff=a-b;
    int i=diff%10;
    if(i<9)
     diff++;
    else
     diff--;
   
    printf("%d",diff);
    return 0;

1 comment: