鱼C论坛

 找回密码
 立即注册
查看: 989|回复: 1

[已解决]新手学习c语言,sin30问题

[复制链接]
发表于 2021-3-31 16:33:15 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
#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

为什么答案这么离谱呢
最佳答案
2021-3-31 16:47:19
本帖最后由 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>
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-3-31 16:47:19 | 显示全部楼层    本楼为最佳答案   
本帖最后由 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>
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-9-21 22:22

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表