当GNU编译器在无限值上打印inf
时,我可以将其更改为不同的输出吗?
#include<stdio.h>
{
float runs = 40.0;
float wickets = 0.0;
printf("Average = %.2f(/*This is the place where I want to print NA
instead of inf*/)", runs / wickets);
return 0;
}
答案 0 :(得分:4)
您无法更改无限值的打印方式。但是你可以检查它并采取相应的行动。
double avg = runs / wickets;
if (isinf(avg)) {
printf("Average = NA\n");
} else {
printf("Average = %.2f\n", avg);
}