我有一个包含一系列数字的文件:9 1 2 1
我试图找出比率 subsum/sum
#include <stdio.h>
void main()
{
double subSum = 0;
double sum = 13;
double num = 0;
double x = 0;
FILE* file = fopen("text.txt", "r");
while (fscanf(file, "%f", &num) > 0)
{
subSum = subSum + num;
x = subSum / sum;
printf("%f",x);
printf("\n");
}
fclose(file);
}
但它一直打印零(0.00000000000)为什么???