jh997 发表于 2021-3-16 16:43:29

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

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

# 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)
{
        intt, 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);
}

jackz007 发表于 2021-3-16 16:47:04

本帖最后由 jackz007 于 2021-3-16 16:57 编辑

#include <stdio.h>
的下一行添加一行
#define _CRT_SECURE_NO_WARNINGS
      下面是我修改的代码
#include<stdio.h>

#define _CRT_SECURE_NO_WARNINGS

int gcd(int a , int b)
{
      int c             ;
      while(b) {
                c = a % b ;
                a = b   ;
                b = c   ;
      }
      return a          ;
}

int main()
{
      int a , b , c                                                   ;
      printf(" enter two numbers : ")                                 ;
      scanf ("%d%d" , & a , & b)                                    ;
      c = gcd(a , b)                                                ;
      printf(" %d is 最大公约数\n%d is 最小公倍数\n" , c , a * b /c ) ;
}
      编译、运行实况
D:\0002.Exercise\C>cl x.c
用于 x86 的 Microsoft (R) C/C++ 优化编译器 19.28.29334 版
版权所有(C) Microsoft Corporation。保留所有权利。

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

/out:x.exe
x.obj

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

D:\0002.Exercise\C>
页: [1]
查看完整版本: vs2019编译 显示 scanf this function or variable mat be unsafe 错误