鱼C论坛

 找回密码
 立即注册
查看: 1171|回复: 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"
  1. #include <stdio.h>
  2. #include <math.h>

  3. #define PI 3.14159265358979323846

  4. int main(void)
  5. {
  6.         double x , s                              ;
  7.         printf("input number: ")                  ;
  8.         scanf("%lf", & x)                         ;
  9.         s = sin(x * PI / 180)                     ;
  10.         printf("sin of %.0lf is %.6lf\n" , x , s) ;
  11. }
复制代码

        编译、运行实况
  1. D:\0002.Exercise\C>g++ -o x x.c

  2. D:\0002.Exercise\C>x
  3. input number: 30
  4. sin of 30 is 0.500000

  5. D:\0002.Exercise\C>
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-3-31 16:47:19 | 显示全部楼层    本楼为最佳答案   
本帖最后由 jackz007 于 2021-3-31 16:50 编辑

      double 的输入输出格式符是 "%lf" ('l' 是英字母 'L' 的小写)不是 "%If"
  1. #include <stdio.h>
  2. #include <math.h>

  3. #define PI 3.14159265358979323846

  4. int main(void)
  5. {
  6.         double x , s                              ;
  7.         printf("input number: ")                  ;
  8.         scanf("%lf", & x)                         ;
  9.         s = sin(x * PI / 180)                     ;
  10.         printf("sin of %.0lf is %.6lf\n" , x , s) ;
  11. }
复制代码

        编译、运行实况
  1. D:\0002.Exercise\C>g++ -o x x.c

  2. D:\0002.Exercise\C>x
  3. input number: 30
  4. sin of 30 is 0.500000

  5. D:\0002.Exercise\C>
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-4-30 12:46

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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