Блог пользователя saurabhkumarfx

Автор saurabhkumarfx, история, 6 лет назад, По-английски
int  main()
{
     int t;
     cin>>t;
    int a,b,c;
    cin>>a>>b>>c;
    double tmp=a+b;
    tmp=tmp/2;
    cout<<tmp<<"!";
}

input is : 1 232444 123233 232434 why it is giving wrong answer:177838; why it is rounding off the value .

  • Проголосовать: нравится
  • -11
  • Проголосовать: не нравится

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

Double type has a precision value predefined, and since your value of temp exceeded that precision amount the output was rounded up (But don't worry in the computations you don't lose the 0.5)

If you wanna set your own precision value check the "iomanip" library, it has 2 functions "fixed" and "setprecision" that can accomplish that.