标签:代码 http dsa class sage sig com ati message
/*
所有c语言代码,都是在LoadRunner中运行;
*/
int getFactorial(int n);
Action()
{
lr_output_message("%d",getFactorial(0));
lr_output_message("%d",getFactorial(5));
lr_output_message("%d",getFactorial(10));
return 0;
}
int getFactorial(int n){
int fac=1;//要赋初值,否则会有异常
int i=1;
if (n ==0) {
fac=1;
}else{
for (;i<=n;i++) {
fac = fac * i;
}
}
return fac;
}
=========================================================
运行结果:
Action.c(10): 1
Action.c(11): 120
Action.c(12): 3628800
=========================================================
2、求1!+2!+.........10!
/*
所有c语言代码,都是在LoadRunner中运行;
*/
int getFactorial(int n);
Action()
{
int n = 10;
int i=1;
int sum = 0;
for (;i<=10;i++) {
sum =sum + getFactorial(i);
}
lr_output_message("%d",sum);
return 0;
}
//函数getFactorial用户计算n!的值
int getFactorial(int n){
int fac=1;//要赋初值,否则会有异常
int i=1;
if (n ==0) {
fac=1;
}else{
for (;i<=n;i++) {
fac = fac * i;
}
}
return fac;
}
标签:代码 http dsa class sage sig com ati message
原文地址:https://www.cnblogs.com/beidou93/p/9716411.html