“%d ”与“%d空格”的区别?
#include <stdio.h>
double Ladder(int i_first,int i_second) //积分程序
{
double width=0.01;
double integral=0;
integral=(i_first+i_second)*width/2.0; //梯形面积
return integral;
}
void main()
{
FILE *fx=fopen("x1.txt","r"); //打开文本x1
unsigned int i_first,i_second;
double final=0;
fscanf(fx,"%d ",&i_first);
while(!feof(fx)) //是否读取完毕
{
fscanf(fx,"%d ",&i_second); //读取赋值
final+=Ladder(i_first,i_second); //积分累加
i_first=i_second;
}
fclose(fx); //关闭文本x
printf("积分为:%lf\n",final );
}
x1中为0-100的连续数(0,1,2,...,100)
为什么在fscanf中,当使用"%d"时,输出结果51.使用"%d ",时,输出50.后者正确