gpt4 book ai didi

c++ - 我的 C++ 程序在代码块中给出了正确的结果,但在 Visual Basic 2005 速成版中给出了错误的结果

转载 作者:行者123 更新时间:2023-11-28 05:16:11 25 4
gpt4 key购买 nike

<分区>

我的 C++ 程序在代码块中给出了正确的结果,但在 Visual Basic 2005 速成版中给出了错误的结果。谁能指导我做错了什么:)谢谢:)这是我使用函数查找阶乘的程序。

#include <iostream>
using namespace std;

int fact( int a)
{
if (a>1)
return a*fact(a-1);
}
int main()
{
cout<<"Enter a number to find its factorial : ";
int a;
cin>>a;
cout<<"Factorial of "<<a<<" is "<<fact(a)<<endl<<endl;
}

代码块结果

Enter a number to find its factorial : 5
Factorial of 5 is 120

Visual Basic 2005 速成版结果

Enter a number to find its factorial : 5
Factorial of 5 is -96

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com