如题所述
第1个回答 2012-06-23
#include<stdio.h>
int cal(int n)
{
int sum=1,i;
for(i=1;i<=n;i++)
sum*=i;
return sum;
}
int main(){
int i,j,sum,k;
i = 2*2;
j=3*3;
sum = cal(i) +cal(j);
return 0;
}
int cal(int n)
{
int sum=1,i;
for(i=1;i<=n;i++)
sum*=i;
return sum;
}
int main(){
int i,j,sum,k;
i = 2*2;
j=3*3;
sum = cal(i) +cal(j);
return 0;
}
第2个回答 2012-06-23
//此方法子要运算一次就可以算出时间复杂度为O(n),n为a, b的较大者
//其他两位作者的要运算两次时间,时间复杂度为O(a + b)
//数据会溢出
#include <stdio.h>
#define COMSWAP(A, B) \
{if (A > B) {long T = A; A = B; B = T;}}
long Fac(long a, long b)
{
long i, count;
long result, fac = 1;
COMSWAP(a, b);
count = a;
for (i = 1; i <= count; ++i) {
fac *= i;
}
result = fac;
for (; i <= b; ++i) {
fac *= i;
}
return result + fac;
}
int main()
{
long a, b;
while (scanf("%ld%ld", &a, &b)) {
a *= a, b *= b;
printf("%ld\n", Fac(a, b));
}
return 0;
}
//其他两位作者的要运算两次时间,时间复杂度为O(a + b)
//数据会溢出
#include <stdio.h>
#define COMSWAP(A, B) \
{if (A > B) {long T = A; A = B; B = T;}}
long Fac(long a, long b)
{
long i, count;
long result, fac = 1;
COMSWAP(a, b);
count = a;
for (i = 1; i <= count; ++i) {
fac *= i;
}
result = fac;
for (; i <= b; ++i) {
fac *= i;
}
return result + fac;
}
int main()
{
long a, b;
while (scanf("%ld%ld", &a, &b)) {
a *= a, b *= b;
printf("%ld\n", Fac(a, b));
}
return 0;
}
第3个回答 2012-06-23
#include <stdio.h>
int factoral(int n)
{
int fact=1;
while(n>1){
fact=fact*n;
n--;
}
return fact;
}
int main()
{
int a,b, m,n,j,k,sum;
scanf("%d%d",&a,&b);
n=b*b;
m=a*a;
sum=factoral(m)+factoral(n);
printf("%d ",sum);
}本回答被网友采纳
int factoral(int n)
{
int fact=1;
while(n>1){
fact=fact*n;
n--;
}
return fact;
}
int main()
{
int a,b, m,n,j,k,sum;
scanf("%d%d",&a,&b);
n=b*b;
m=a*a;
sum=factoral(m)+factoral(n);
printf("%d ",sum);
}本回答被网友采纳