33,311
社区成员
发帖
与我相关
我的任务
分享
/****************************************************************************************/
/*题目:请编写一个程序,读取一个double类型的x值和字符类型的变量 T,其中x表示的是以弧度 */
/* 为单位的角,T表示的是三角函数的类型,然后显示如下值: */
/* */
/* (a) sin(x), 如果把s或S赋给T; */
/* (b) cos(x), 如果把c或C赋给T; */
/* (c) tan(x), 如果把t或T赋给T; */
/* 请分别使用以下语句来实现: */
/* (i) if...else语句; */
/* (ii) switch语句; */
/* */
/*时间:2009.06.02 */
/****************************************************************************************/
#include <stdio.h>
#include <math.h>
int main(void)
{
double x;
char T;
printf("\nplease input T and x (eg:x=3.141593 T=s ):\n\n");
printf("x=");
scanf("%lf",&x);
printf("T="); // 1)
scanf("%c",&T); // 2)
if (T=='s'||T=='S')
printf("\nx=%lf\tsin(x)=%lf\n\n",x,sin(x));
else if (T=='c'||T=='C')
printf("\nx=%lf\tcos(x)=%lf\n\n",x,cos(x));
else if (T=='t'||T=='T')
printf("\nx=%lf\ttan(x)=%lf\n\n",x,tan(x));
else
printf("\ndata error,invalid T!\n\n");
return 0;
}
/****************************************************************************************/
/*题目:请编写一个程序,读取一个double类型的x值和字符类型的变量 T,其中x表示的是以弧度 */
/* 为单位的角,T表示的是三角函数的类型,然后显示如下值: */
/* */
/* (a) sin(x), 如果把s或S赋给T; */
/* (b) cos(x), 如果把c或C赋给T; */
/* (c) tan(x), 如果把t或T赋给T; */
/* 请分别使用以下语句来实现: */
/* (i) if...else语句; */
/* (ii) switch语句; */
/* */
/*时间:2009.06.02 */
/****************************************************************************************/
/**解法1*********************************************************************************/
/*
#include <stdio.h>
#include <math.h>
int main(void)
{
double x;
char T;
printf("\nplease input T and x (eg:T=s x=3.141593):\n\n");
printf("x=");
scanf("%lf",&x);
fflush(stdin);
// getchar(); //用fflush(stdin)吧!
printf("T=");
scanf("%c",&T);
if (T=='s'||T=='S')
printf("\nx=%lf\tsin(x)=%lf\n\n",x,sin(x));
else if (T=='c'||T=='C')
printf("\nx=%lf\tcos(x)=%lf\n\n",x,cos(x));
else if (T=='t'||T=='T')
printf("\nx=%lf\ttan(x)=%lf\n\n",x,tan(x));
else
printf("\ndata error,invalid T!\n\n");
return 0;
}
*/
/**解法2*********************************************************************************/
#include <stdio.h>
#include <math.h>
int main(void)
{
double x;
char T;
printf("\nplease input T and x (eg:T=s x=3.141593):\n\n");
printf("x=");
scanf("%lf",&x);
fflush(stdin);
// getchar(); //用fflush(stdin)吧!
printf("T=");
scanf("%c",&T);
switch (T)
{
case 's':
case 'S':
printf("\nx=%lf\tsin(x)=%lf\n\n",x,sin(x));
break;
case 'c':
case 'C':
printf("\nx=%lf\tcos(x)=%lf\n\n",x,cos(x));
break;
case 't':
case 'T':
printf("\nx=%lf\ttan(x)=%lf\n\n",x,tan(x));
break;
default:
printf("\ndata error,invalid T!\n\n");
}
return 0;
}