用C语言编程:sum=1+2*3+4*5*6+7*8*9*10+…… 共n项,n由键盘输入
7个回答
展开全部
#include<stdio.h>
unsigned long mysum(int n)
{
int i;
int count;
int k;
unsigned long sumTemp,sum;
i=1;k=1;sum=0;
while(i<=n)
{
count=0;sumTemp=1;
while(count<k & i<=n)
{
sumTemp=sumTemp*i;
i++;
count++;
}
/*printf("%ld\n",sumTemp); */
sum=sum+sumTemp;
k++;
}
return sum;
}
int main()
{
int n;
printf("input n:\n\n");
scanf("%d",&n);
printf("%ld\n",mysum(n));
getch();
return 0;
}
unsigned long mysum(int n)
{
int i;
int count;
int k;
unsigned long sumTemp,sum;
i=1;k=1;sum=0;
while(i<=n)
{
count=0;sumTemp=1;
while(count<k & i<=n)
{
sumTemp=sumTemp*i;
i++;
count++;
}
/*printf("%ld\n",sumTemp); */
sum=sum+sumTemp;
k++;
}
return sum;
}
int main()
{
int n;
printf("input n:\n\n");
scanf("%d",&n);
printf("%ld\n",mysum(n));
getch();
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询