我不知道为什么它说它需要一段时间或放在哪里,它给出了LOCS功能的错误答案,我也可以做任何关于默认指针警告的事情。这只是一个开始,我将在稍后进行扩展,这将是一个很大的帮助,我已经尝试过(%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;
}
答案 0 :(得分: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