我写的是
#include "stdafx.h"#using <mscorlib.dll>
#include <tchar.h>using namespace System;int _tmain(void)
{
long Stage(int n);
int n=1;
{
if (n <= 1)
n=1; else
n=n * Stage(n - 1);
return n;
}}怎么不行??
有更好的吗?
#include "stdafx.h"#using <mscorlib.dll>
#include <tchar.h>using namespace System;int _tmain(void)
{
long Stage(int n);
int n=1;
{
if (n <= 1)
n=1; else
n=n * Stage(n - 1);
return n;
}}怎么不行??
有更好的吗?
syl08341(沈阳老零) Thanks
要怎么做成windows窗口?
不过这是非常简单的。如果需要的话,你自己加上。
#include <stdio.h>int jeicheng(int n)
{
if(n == 1)
return 1;
else
return jeicheng(n-1) * n;
}void main()
{
int n;
printf("请输入数字N:");
scanf("%d", &n);
int result = jeicheng(n);
printf("%d的结乘是%d\n", n, result);
}
建立一个基于对话框的应用程序。
加上一个按钮。然后OnButton
然后在里面加入上述代码。
把他移到任何函数外,在main里调用你的递归函数
非递归:
int nn(int n)
{
int r=1;
for(int i=2;i<=n;i++)
r*=i;
return r;
}
{
return n==1?1:xx(n-1)*n;
}