我是编程新手,尝试通过自己学习,我的代码有错误,我不明白这是一个语法错误,或者我犯了错误。我使用了3个方程这是它的条件,并且是为了isntruction而做的,而do-while,if-else,with switch.After我介绍了变量a后,它向我展示了一个错误“退出非零状态”。退出非零状态
#include <stdio.h>
#include <math.h>
int main() {
float a,x,b;
float L;
int m;
printf("Enter variables a,x,b:");
scanf("%f%f%f,&a,&x,&b");
printf("For using for instruction (enter 1)");
printf("For using while instruction (enter 2)");
printf("For using do-while instruction (enter 3)");
printf("For using ef instruction (enter 4)");
scanf("%d,&m");
switch(m){
case 1:
for (x=0;x<1.2;x++)
{
L=2*cos(x-(3.14/6));
}
for (x=0;x>= 1.2 && x<=3.9;x++)
{
L=x*x/(a+cos(powf((x+b),3)));
}
for (x=0;x>3.9;x++)
{
L=fabs(x/2*a)+powf(sin(x+1),2);
}
break;
case 2:
while (x<1.2)
{
L=2*cos(x-(3.14/6));
}
while (x>= 1.2 && x<=3.9)
{
L=x*x/(a+cos(powf((x+b),3)));
}
while (x>3.9)
{
L=fabs(x/2*a)+powf(sin(x+1),2);
}
break;
case 3:
do
{
L=2*cos(x-(3.14/6));
}
while (x<1.2);
do
{
L=x*x/(a+cos(powf((x+b),3)));
}
while (x>= 1.2 && x<=3.9);
do
{
L=fabs(x/2*a)+powf(sin(x+1),2);
}
while (x>3.9);
break;
case 4:
if (x<1.2)
{
L=2*cos(x-(3.14/6));
}
else
{
printf("First statement is false");
}
if(x>= 1.2 && x<=3.9)
{
L=x*x/(a+cos(powf((x+b),3)));
}
else
{
printf("Second statement is false");
}
if(x>3.9)
{
L=fabs(x/2*a)+powf(sin(x+1),2);
}
else
{
printf("Third statement is false");
}
break;
default:
printf("\nNo right choices\n");
}
printf("Your answer is: L = %.3f,L");
}
是否执行到达终点? – Neo
欢迎来到堆栈溢出!请[编辑]你的代码,以减少它到你的问题[mcve]。您当前的代码包含很多与您的问题相关的代码 - 通常,最小样本看起来与单元测试相似:只执行一项任务,输入值指定为可重现性。 –
@TomKarzes不正确。见5.1.2.2.3节目终止,C标准第1段。 “...到达终止'main'函数的'}'返回值为0。 (这确实假定正在使用的编译器符合C99(或更高版本)...) –