gpt4 book ai didi

c - 以非零状态退出

转载 作者:行者123 更新时间:2023-11-30 20:00:18 25 4
gpt4 key购买 nike

我是编程新手,尝试自己学习,我的代码中有一个错误,我不明白这是一个语法错误,或者我做错了。我使用了 3 个方程式及其条件并制作了它在 for istruction、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,但它没有任何地址可将值放入其中。或者更准确地说,它从垃圾中找到它需要的值(了解堆栈和参数的动态数量),因为您没有插入它。

关于c - 以非零状态退出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46603646/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com