《算法竞赛入门经典》CH1

2016-05-24  本文已影响48人  洛朗不展傅立叶

mac, Xcode
一些无法得到理想结果的代码和实际输出样式

  1. no mistake
printf(“%f\n", sqrt(-10));

nan

  1. no mistake
printf("%f\n", 1.0/0.0);

inf

#include <stdio.h>
#include <math.h>
int main()
{   
    //no mistake
    printf("%f\n", 0.0/0.0);

    //no mistake, but warn
    //int isn't corresponded with double
    printf("%f\n", 0/0);

    //division by zero is undefined
    printf("%d\n", 0/0);
    return 0;
}

nan
nan
73823

  1. Two warn that division by zero is undefined
printf("%d\n", 1/0);
printf("%d\n", 0/0);

1606416392

上一篇下一篇

猜你喜欢

热点阅读