gpt4 book ai didi

c - 预计在 elseif 之前

转载 作者:行者123 更新时间:2023-11-30 21:11:14 27 4
gpt4 key购买 nike

我不知道为什么它说需要一段时间或将其放在哪里,并且它为 LOCS 函数提供了错误的答案,对于默认指针警告我可以做些什么。这只是一个开始,我稍后会扩展它,所以这将是一个很大的帮助,我已经尝试了 while (%s != '\0')

#include <stdio.h>
#include <math.h>
#define SQUARE(x) x * x

float LOCS (float a, float b, float c) //Law Of CoSines
{
float d, e, f, g;
d = SQUARE(a) + SQUARE(b);
double cos (double);
double sqrt (double);
e = 2 * (b * a);
f = d - (e * cos(c));
g = sqrt(f);
return g;
}
float PythagoreanTherom (float a, float b)
{
float c, result;
double sqrt (double);
c = SQUARE(a) + SQUARE(b);
result = sqrt(c);
return result;
}
int main (void)
{
float sidea, sideb, angle, result;
char array[81];
float LOCS (float a, float b, float c);
float PythagoreanTherom (float a, float b);
printf("Type what you would like to do\n");
scanf("%s", &array[81]);
if (array[81] = "LawOfCosines") do {
printf("Print the two known sides then the angle \
pressing enter after each.\n");
scanf("%f", &sidea);
scanf("%f", &sideb);
scanf("%f", &angle);
result = LOCS(sidea,sideb,angle);
printf("The third side is %f", result);
}
elseif (array[81] = "PythagoreanTherom") do {
printf("Type enter after the \
input of each leg\n");
scanf("%f", &d);
scanf("%f", &e);
f = pt(d,e);
printf("The hypotenuse is %.2f", f);
}
return 0;
}

最佳答案

使用此代码。我对您的代码做了一些更改

#include <stdio.h>
#include <math.h>
#include<string.h>
#define SQUARE(x) (x) * (x)
float LOCS (float a, float b, float c) //Law Of CoSines
{
float d, e, f, g;
d = SQUARE(a) + SQUARE(b);
double cos (double);
double sqrt (double);
e = 2 * (b * a);
f = d - (e * cos(c));
g = sqrt(f);
return g;
}
float PythagoreanTherom (float a, float b)
{
float c, result;
double sqrt (double);
c = SQUARE(a) + SQUARE(b);
result = sqrt(c);
return result;
}

int main (void)
{
float sidea, sideb, angle, result,d,e,f; // you didn't declare the d,e,f variables
char array[81];
float LOCS (float a, float b, float c);
float PythagoreanTherom (float a, float b);
printf("Type what you would like to do\n");
scanf("%s",array);
if (strcmp(array,"LawOfCosines")==0){ // no need of do while loop here // for comparing two strings you should not use == operator to compare. use string functions or implement your own function
printf("Print the two known sides then the angle \
pressing enter after each.\n");
scanf("%f", &sidea);
scanf("%f", &sideb);
scanf("%f", &angle);
result = LOCS(sidea,sideb,angle);
printf("The third side is %f", result);
}
else if (strcmp(array, "PythagoreanTherom")==0){ // no need of do- while loop here
printf("Type enter after the \
input of each leg\n");
scanf("%f", &d);
scanf("%f", &e);
f = PythagoreanTherom(d,e); // call the function with the same name as it is in definition
printf("The hypotenuse is %.2f", f);
}
return 0;
}

在编译代码时使用 -lm 链接,因为您正在使用数学库。

cc filename.c -lm

关于c - 预计在 elseif 之前,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24877355/

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