sahasumit288's blog

By sahasumit288, history, 10 years ago, In English

UVA -1177

I need to convert a double number to an integer and print it. Let ans is that double number. Now,if I write


printf("%0.lf\n",&ans);

I got accepted. But instead if write

cout<<(int)ans<<"\n";

I got wrong answer.

Can anyone explain it?

  • Vote: I like it
  • +3
  • Vote: I do not like it

»
10 years ago, hide # |
Rev. 4  
Vote: I like it +10 Vote: I do not like it

printf("%.0lf\n", ans) prints round(ans), but if you write (int)ans it will be floor(ans)