鱼C论坛

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

vs2019编译 显示 scanf this function or variable mat be unsafe 错误

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

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

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

x
输入;两个数  求他们的最大公约数和最小公倍数

# include<stdio.h>
int main()
{
        int f1(int , int );
        int f2(int , int ,int);
        int a, b,c,d;
        printf(" enter two numbers:\n");
        scanf ("%d %d", &a, &b);
        c = f1(a, b);
        d = f2(a, b,c);
        printf(" %d is 最大公约数\n%d is 最小公倍数", c, d);
        return 0;
}

int f1(int x, int y)
{
        int  t, temp;
        if (x < y)
        {
                temp= x;
                x = y;
                y = temp;
        }

        while (y != 0)
        {
                t = x % y;
                x = y;
                y = t;

        }
        return (x);

}

int f2(int x, int y,int c)
{
        return (x* y / c);
}
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-3-16 16:47:04 | 显示全部楼层
本帖最后由 jackz007 于 2021-3-16 16:57 编辑
  1. #include <stdio.h>
复制代码

的下一行添加一行
  1. #define _CRT_SECURE_NO_WARNINGS
复制代码

        下面是我修改的代码
  1. #include<stdio.h>

  2. #define _CRT_SECURE_NO_WARNINGS

  3. int gcd(int a , int b)
  4. {
  5.         int c             ;
  6.         while(b) {
  7.                 c = a % b ;
  8.                 a = b     ;
  9.                 b = c     ;  
  10.         }
  11.         return a          ;
  12. }

  13. int main()
  14. {
  15.         int a , b , c                                                   ;
  16.         printf(" enter two numbers : ")                                 ;
  17.         scanf ("%d%d" , & a , & b)                                      ;
  18.         c = gcd(a , b)                                                  ;
  19.         printf(" %d is 最大公约数\n%d is 最小公倍数\n" , c , a * b /c ) ;
  20. }
复制代码

        编译、运行实况
  1. D:\0002.Exercise\C>cl x.c
  2. 用于 x86 的 Microsoft (R) C/C++ 优化编译器 19.28.29334 版
  3. 版权所有(C) Microsoft Corporation。保留所有权利。

  4. x.c
  5. Microsoft (R) Incremental Linker Version 14.28.29334.0
  6. Copyright (C) Microsoft Corporation.  All rights reserved.

  7. /out:x.exe
  8. x.obj

  9. D:\0002.Exercise\C>x
  10. enter two numbers : 48 64
  11. 16 is 最大公约数
  12. 192 is 最小公倍数

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

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-4-30 22:02

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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