一段小程序,求帮忙改错
#include <stdio.h>void main(){ float x,y; printf("输入x:\n"); scanf("%f\n",&x); if(x<1) { y=x; printf("%f\n",y); } else if(x>=10) { y=3*x-11; printf("%f\n",y); } else { y=2*x-1; printf("%f\n",y); }} printf("输入x:\n"); scanf("%f",&x);
[解决办法]
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
void main()
{
float x,y;
printf("输入x:\n");
scanf("%f",&x);
if(x<1)
{
y=x;
printf("%f\n",y);
}
else if(x>=10)
{
y=3*x-11;
printf("%f\n",y);
}
else
{
y=2*x-1;
printf("%f\n",y);
}
system("pause");
}
[解决办法]
输入 不能有\n
[解决办法]
scanf是格式输入函数,双引号中是你输入的变量的格式,不要加变量名、等号、回车符一类的,scanf不认识它们