c语言编程运行失败的提问

各位亲,麻烦看一下,这个为啥无法正常运行啊,编程软件是vs2022

//factor.c--使用循环和递归计算阶乘
#include<stdio.h>
long fact(int n);
long rfact(int n);

int main(void)
{
    int num;
    
    printf("This program calculates factorials.\n");
    printf("Enter a value in the range 0-12 (q to quit):\n");
    while (scanf_s(" % d", &num) == 1)
    {
        if (num < 0)
            printf("No negative numbers, please.\n");
        else if (num > 12)
            printf("Keep input under 13.\n");
        else
        {
            printf("loop: %d factorical =%ld\n", num, fact(num));//循环
            printf("recursion: %d factorical =%ld\n", num,rfact(num));//递归
        }
        printf("Enter a value in the range 0-12 (q to quit):\n");
    }
    printf("Bye.\n");
    return 0;
}
long fact(int n) 
{
    long ans;
    for (ans=1;n>1;n--)
        ans *= n;
    return ans;
}
long rfact(int n)
{
    long ans;
    if (n > 0)
        ans = n * rfact(n - 1);
    else
        ans = 1;
    return ans;
}

img

while (scanf_s(" % d", &num) == 1)

不要空格

while (scanf_s(" %d", &num) == 1)

不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^