#include <stdio.h>
#include <stdlib.h>
#define f(x) (1 / (x*x+1))
int main(){
double a,b,h,x,y;
printf("Enter a, b, h: ");
scanf(" %lf %lf %lf " , &a, &b, &h);
// I ask for 3 inputs but the programm needs 4 to run...why is that?
x = a;
while(x<b)
{
y = f(x);
printf("%lf %lf \n", x ,y );
x +=h;
}
system("Pause");
return(0);
}
Run Code Online (Sandbox Code Playgroud)
问题出在你的scanf上:
scanf(" %lf %lf %lf " , &a, &b, &h);
^
Run Code Online (Sandbox Code Playgroud)
scanf需要查看下一个非空格以确定此"0或更多空格"的结尾,因此您必须提供第4个值(它可以是垃圾 - 只要它不是空格)scanf来终止输入.
如果您在Windows上,可以在新行上按Ctrl-Z并按Enter键.这将向程序发送EOF,也可以终止输入.(我想你是在Windows上,因为我system("pause")在你的程序中看到了)
| 归档时间: |
|
| 查看次数: |
85 次 |
| 最近记录: |