[英]exited with non-zero status
我是编程新手,并尝试自己学习,我的代码中有错误,我不明白这是语法错误,或者我做错了。我使用了 3 个带有条件的方程并将其输入为非结构,while,do-while,if-else,with switch。在我引入变量 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");
}
您的问题是您的scanf
参数格式不正确。
而不是scanf("%f%f%f,&a,&x,&b");
使用scanf("%f%f%f",&a,&x,&b);
. 在第二个scanf
相同。
变量地址是参数,而不是字符串的一部分。
当你调用它时, scanf
找到第一个%f
但它没有任何地址可以放入值。 或者更准确地说,它从垃圾中找到它需要的值(阅读堆栈和参数的动态数量),因为你没有插入它。
scanf("%f%f%f,&a,&x,&b")
; 应该是这样scanf("%f%f%f",&a,&x,&b);
. 请更正您使用过 scanf 的地方。 由于语法错误,您的代码没有接受用户的输入。 我已经编译并尝试它正确运行。 请在任何地方更改 scanf 语法。
scanf("%f%f%f,&a,&x,&b")
到scanf("%f%f%f",&a,&x,&b)
scanf("%d,&m");
到scanf("%d",&m);
printf("Your answer is: L = %.3f,L");
to printf("Your answer is: L = %.3f",L);
你错过了 return 0; main 函数末尾的语句。 由于c main函数是int main()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.