zarif_2002's blog

By zarif_2002, history, 6 years ago, In English

1076C - Meme Problem ~~~~~

include<stdio.h>

include<math.h>

int main(){

int a,t,i;

double y,z;

scanf("%d",&t);

for(i = 0; i < t; i++){

    scanf("%d",&a);

    if(a == 1 || a==2 || a==3){

        printf("N\n");
    }
    else{
        y = ((double)a + sqrt((double)a*(double)a - 4*(double)a))/2;

        z = ((double)a - sqrt((double)a*(double)a - 4*(double)a))/2;

        printf("Y %0.9lf %0.9lf\n",y,z);
    }
}
return 0;

} ~~~~~

gets AC in GNU C++11 but gets WA in C. though I wrote it in C syntax. how?

  • Vote: I like it
  • -17
  • Vote: I do not like it

»
6 years ago, # |
Rev. 3   Vote: I like it +8 Vote: I do not like it

GNU C doesn't support %lf modificator as far as I know. You should use %f instead. It's correct write doubles as %f in GNU C. Though in GNU C++ it's not correct and you need %lf for doubles.

P.S. I dont know why downvoting. Really interesting question and I hope there will appear GNU masters to correct me since I'm not quite sure.

»
6 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

http://www.cplusplus.com/reference/cstdio/printf/ says you cannot write 'lf'. Use 'f' instead.