|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
程序
#include <stdio.h>
#include <math.h>
void main()
{
double x, s;
printf("input number:\n");
scanf("%1f", &x);
s = sin(x);
printf("sin of %1f is %1f\n", x, s);
}
启动后的结果
input number:
30
sin of -92559604425286806000000000000000000000000000000000000000000000.000000 is -0.048960
Press any key to continue
ps. 这个程序似乎是求未知数的sin用的,我输入的未知数是30, 但是结果却根30 没有任何关系。作为初学者,我无法凭借自己解决问题,所以诚信求助。
本帖最后由 昨非 于 2020-12-26 14:45 编辑
- #include <stdio.h>
- #include <math.h>
- void main()
- {
- double x, s;
- printf("input number:\n");
- scanf("%lf", &x); //%lf,l是L的小写,不是数字1
- s = sin(x);
- printf("sin of %lf is %lf\n", x, s);
- }
复制代码
如果要限制位数,可以
- #include <stdio.h>
- #include <math.h>
- void main()
- {
- double x, s;
- printf("input number:\n");
- scanf("%lf", &x);
- s = sin(x);
- printf("sin of %.3lf is %.3lf\n", x, s); //显示三位小数
- }
复制代码
测试结果:
- input number:
- 30
- sin of 30.000 is -0.988
复制代码
|
|