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

×

Ceil A-B ,What's wrong with my code ?

//It's the code for Ceil A-B problem in practice set

#include<stdio.h>

int main()
{
    unsigned long a=0;
    unsigned long b=0;
        scanf("%lu %lu", &a, &b);
        printf("%lu\n",(a-b));
        printf("%lu\n", (a-b)^1);
    return 0;
}

asked 13 May '14, 13:56

cdamo57's gravatar image

1★cdamo57
54
accept rate: 0%

edited 14 May '14, 10:03

kunal361's gravatar image

4★kunal361
6.0k133272

remove printf("%lu\n",(a-b)^1); because we can not write ^

(13 May '14, 22:59) deepanil0280★

You should not output the first line i.e. remove printf("%lu\n",(a-b)) .

link

answered 13 May '14, 14:22

the65bit's gravatar image

4★the65bit
1.1k101328
accept rate: 13%

edited 13 May '14, 14:22

When a-b = 1 your answer will be zero , but it has leading zeroes . So it is giving WA . Here is your corrected code .

# include < stdio.h>
int main()
{
    unsigned long a=0;
    unsigned long b=0;
    unsigned long ans=0;
    scanf("%lu %lu", &a, &b);
    ans=(a-b)^1;
    if (ans==0)
        ans=2;
    printf("%lu\n",ans); return 0;
}
link

answered 13 May '14, 23:30

the65bit's gravatar image

4★the65bit
1.1k101328
accept rate: 13%

edited 14 May '14, 10:05

kunal361's gravatar image

4★kunal361
6.0k133272

Thanks. I forgot that fact. Now ok. Once again thank you.

(15 May '14, 13:00) cdamo571★
#include<stdio.h>

int main()
{
    unsigned long a=0;
    unsigned long b=0;
        scanf("%lu %lu", &a, &b);
        printf("%lu\n", (a-b)^1);
    return 0;
}

Again wrong... What can i do ? My way of implementation is correct ?

link

answered 13 May '14, 21:56

cdamo57's gravatar image

1★cdamo57
54
accept rate: 0%

edited 14 May '14, 10:03

kunal361's gravatar image

4★kunal361
6.0k133272

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:

×538
×7
×6

question asked: 13 May '14, 13:56

question was seen: 701 times

last updated: 15 May '14, 15:10