You are not logged in. Please login at www.codechef.com to post your questions!

×

ceil and a-b problem ?? can any1 find bug in this code??

include <iostream>

include<stdio.h>

using namespace std;

int main() {

int a , b;

scanf("%d%d",&a,&b);

int c = a-b;

c= (c/10)*10 + (c%10 + 1)%10;

printf("%d\n",c);
return 0;

}

I AM JUST CHANGING LAST DIGIT OF CODE TO INCREMENT BY 1 , IF THE LAST DIGIT IS 9 THEN IT IS REPLACED BY 0

asked 25 Jan '15, 11:43

keshav_1994's gravatar image

0★keshav_1994
115
accept rate: 0%

edited 25 Jan '15, 11:52


I think your code is failing for the following test case :

10 1

Your code will give 0 as the answer while 0 can't be. You can simply do it like, find the difference and if the difference%10 is 9, then print diff-1 else print diff+1.

link

answered 25 Jan '15, 11:56

damn_me's gravatar image

3★damn_me
2.6k21336
accept rate: 24%

yeahhh got you !!!!

link

answered 25 Jan '15, 12:00

keshav_1994's gravatar image

0★keshav_1994
115
accept rate: 0%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×856
×135
×10
×8
×2

question asked: 25 Jan '15, 11:43

question was seen: 981 times

last updated: 28 May '16, 21:49