# include <stdio.h>
# include <math.h>
# define pi 3.1415926
int main(void)
{
double a,n,j;
printf("enter 三角函数名:");
scanf("%lf",&j);
printf("enter a:");
scanf("%lf",&a);
n=pi*a/180;
if(j=sin)
j=sin(n);
if(j=cos)
j=cos(n);
if(j=tan)
j=tan(n);
printf("%f",j);
return 0
;
}
问题在哪里?
第1个回答 2015-04-29
# include <stdio.h>
# include <math.h>
# define pi 3.1415926
int main(void)
{
double a,n,result;
char func_name[3];
printf("enter the name of triangle function :");
scanf("%s",&func_name);
printf("enter angel:");
scanf("%lf",&a);
n=pi*a/180;
if (strcmp(func_name, "sin") == 0)
result=sin(n);
if (strcmp(func_name, "cos") == 0)
result=cos(n);
if (strcmp(func_name, "tan") == 0)
result=tan(n);
printf("%0.2f\n",result);
return 0
;
}追问
# include <math.h>
# define pi 3.1415926
int main(void)
{
double a,n,result;
char func_name[3];
printf("enter the name of triangle function :");
scanf("%s",&func_name);
printf("enter angel:");
scanf("%lf",&a);
n=pi*a/180;
if (strcmp(func_name, "sin") == 0)
result=sin(n);
if (strcmp(func_name, "cos") == 0)
result=cos(n);
if (strcmp(func_name, "tan") == 0)
result=tan(n);
printf("%0.2f\n",result);
return 0
;
}追问
求解释那个strcmp哪里来的
追答c自带库函数,将两个字符串比较,相等返回为0
第2个回答 2015-04-29
看你的代码的话,j应该是字符串吧?怎么能用%lf格式输入呢。。。追问
怎么看是字符串的
第3个回答 2015-04-29
j是字符串吧
char j[4];
scanf("%s",j);
if(j=="sin")
if(j=="cos")追问
char j[4];
scanf("%s",j);
if(j=="sin")
if(j=="cos")追问
为什么是字符串