为什么我这个输出的结果是2????大神指导
#include <stdio.h>long square(int p);//函数平方
long factorial(int q);//函数阶层
void main()
{
int i;
long s = 0;
for(i=2; i <= 3; i++)
{
s = s + square(i);
}
//s = square(2) + square(3);
printf("%ld\n", s);
}
long square(int p)
{
int k;
long r;
long factorial(int);
k = p * p;
r = factorial(k);
return r;
}
long factorial(int q)
{
long c = 1;
int i;
for(i=1; i <= q; i++)
{
c *= i;
return c;
}
} #include <stdio.h>
long long square(long long p)
{
long long k , r ;
for(r = 1 , k = 1 ; k <= p * p ; k ++) r *= k ;
return r ;
}
int main(void)
{
long long i , s ;
for(s = 0 , i = 2 ; i <= 3 ; i ++) s += square(i) ;
printf("%I64d\n", s) ;
}
编译运行实况:
D:\00.Excise\C>g++ -o x x.c
D:\00.Excise\C>x
362904
D:\00.Excise\C> long factorial(int q)
{
long c = 1;
int i;
for (i = 1; i <= q; i++)
{
c *= i;
}
return c;
}
你是不是Return 写错地方了? jackz007 发表于 2020-11-9 22:44
编译运行实况:
谢谢大哥! 4goodworld 发表于 2020-11-9 22:53
你是不是Return 写错地方了?
确实return写错了,问题解决,谢谢大哥!!!{:5_108:}
页:
[1]