展开全部
#include <stdio.h>
#define N 2
int main()
{
int sum,i,j,a;
sum=0;
a=0;
for(i=1;i<=N;i++)
{
for(j=1,a=0;j<=i;j++) a=a+j;
sum=sum+a;
}
printf("sum=%d\n",sum);
return 0;
}
可以改变#define N 后面的数值来实现改变.
#define N 2
int main()
{
int sum,i,j,a;
sum=0;
a=0;
for(i=1;i<=N;i++)
{
for(j=1,a=0;j<=i;j++) a=a+j;
sum=sum+a;
}
printf("sum=%d\n",sum);
return 0;
}
可以改变#define N 后面的数值来实现改变.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这题很简单的吧!
我帮你写个:
#include <stdio.h>
long factorial(long n)
{
if (n == 0 || n == 1)
return 1;
else
return n * factorial(n-1);
}
void PrintResult(int n, long result)
{
int i = 0;
if (n == 0)
printf("%d! = ", 0);
else if (n == 1)
printf("%d! = ", 1);
else if (n == 2)
printf("%d!+%d! = ", 1, 2);
else
printf("%d!+%d!+...+%d! = ", 1, 2, n);
printf("%lu\n", result);
}
int main(void)
{
int n = 0, i = 0;
long sum = 0;
printf("Please input a number: \n");
scanf("%d", &n);
for (i = 1; i <= n; i++)
{
sum += factorial(i);
}
PrintResult(n, sum);
return 0;
}
例子:
Please input a number:
20
1!+2!+...+20! = 268040729
Press any key to continue
我帮你写个:
#include <stdio.h>
long factorial(long n)
{
if (n == 0 || n == 1)
return 1;
else
return n * factorial(n-1);
}
void PrintResult(int n, long result)
{
int i = 0;
if (n == 0)
printf("%d! = ", 0);
else if (n == 1)
printf("%d! = ", 1);
else if (n == 2)
printf("%d!+%d! = ", 1, 2);
else
printf("%d!+%d!+...+%d! = ", 1, 2, n);
printf("%lu\n", result);
}
int main(void)
{
int n = 0, i = 0;
long sum = 0;
printf("Please input a number: \n");
scanf("%d", &n);
for (i = 1; i <= n; i++)
{
sum += factorial(i);
}
PrintResult(n, sum);
return 0;
}
例子:
Please input a number:
20
1!+2!+...+20! = 268040729
Press any key to continue
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include<stdio.h>
void
main()
{
long
i,n,num=1,result=0;
printf("Please
input
a
num:");
scanf("%ld",&n);
for(i=1;i<=n;i++)
{
num*=i;
result+=num;
}
printf("result=%ld",result);
getch();
}
void
main()
{
long
i,n,num=1,result=0;
printf("Please
input
a
num:");
scanf("%ld",&n);
for(i=1;i<=n;i++)
{
num*=i;
result+=num;
}
printf("result=%ld",result);
getch();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询