新手学习c语言,sin30问题
#include <stdio.h>#include <math.h>
void main()
{
double x, s;
printf("input number:\n");
scanf("%If", &x);
s = sin(x);
printf("sin of %If is %If\n", x, s);
}
sin of -3105036184601417870297958976925005110513772034233393222278104076052101905372753772661756817657292955900975461394262146412343160088229628782888574550082362278408909952041699811100530571263196889650525998387432937501785693707632115712.000000 is 0.777342
为什么答案这么离谱呢{:10_269:} 本帖最后由 jackz007 于 2021-3-31 16:50 编辑
double 的输入输出格式符是 "%lf" ('l' 是英字母 'L' 的小写)不是 "%If"
#include <stdio.h>
#include <math.h>
#define PI 3.14159265358979323846
int main(void)
{
double x , s ;
printf("input number: ") ;
scanf("%lf", & x) ;
s = sin(x * PI / 180) ;
printf("sin of %.0lf is %.6lf\n" , x , s) ;
}
编译、运行实况
D:\0002.Exercise\C>g++ -o x x.c
D:\0002.Exercise\C>x
input number: 30
sin of 30 is 0.500000
D:\0002.Exercise\C>
页:
[1]