1、编写一个函数求n!,然后利用该函数计算1!+2!+3!+…+n!的值。
1个回答
展开全部
#include<stdio.h>
main()
{
int
n,i,j,sum1,sum=0,gongzi,hundred,fifty,ten,five,two,one;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
sum1=1;
for(j=1;j<=i;j++)
{
for(j=1;j<=i;j++)
{
sum1=sum1*j;
}
printf("%d的阶乘为%d\n",j-1,sum1);
}
sum=sum+sum1;
}
printf("1到%d的阶乘和sum=%d\n",n,sum);
scanf("%d",&gongzi);
hundred=gongzi/100;
fifty=gongzi%100/50;
ten=gongzi%100%50/10;
five=gongzi%100%50%10/5;
two=gongzi%100%50%10%5/2;
one=gongzi%100%50%10%5%2/1;
//printf("%d元分别要一百元、五十元、十元、五元、二元和一元的抄票数为:\n%d,
%d,
%d,
%d,
%d,
%d\n",gongzi,hundred,fifty,ten,five,two,one);
printf("%d元工资有:\n",gongzi);
if(hundred!=0)
{
printf("%d张百元,
",hundred);
}
if(fifty!=0)
{
printf("%d张五十元,
",fifty);
}
if(ten!=0)
{
printf("%d张十元,
",ten);
}
if(five!=0)
{
printf("%d张五元,
",five);
}
if(two!=0)
{
printf("%d张二元,
",two);
}
if(one!=0)
{
printf("%d张一元\n",one);
}
}
main()
{
int
n,i,j,sum1,sum=0,gongzi,hundred,fifty,ten,five,two,one;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
sum1=1;
for(j=1;j<=i;j++)
{
for(j=1;j<=i;j++)
{
sum1=sum1*j;
}
printf("%d的阶乘为%d\n",j-1,sum1);
}
sum=sum+sum1;
}
printf("1到%d的阶乘和sum=%d\n",n,sum);
scanf("%d",&gongzi);
hundred=gongzi/100;
fifty=gongzi%100/50;
ten=gongzi%100%50/10;
five=gongzi%100%50%10/5;
two=gongzi%100%50%10%5/2;
one=gongzi%100%50%10%5%2/1;
//printf("%d元分别要一百元、五十元、十元、五元、二元和一元的抄票数为:\n%d,
%d,
%d,
%d,
%d,
%d\n",gongzi,hundred,fifty,ten,five,two,one);
printf("%d元工资有:\n",gongzi);
if(hundred!=0)
{
printf("%d张百元,
",hundred);
}
if(fifty!=0)
{
printf("%d张五十元,
",fifty);
}
if(ten!=0)
{
printf("%d张十元,
",ten);
}
if(five!=0)
{
printf("%d张五元,
",five);
}
if(two!=0)
{
printf("%d张二元,
",two);
}
if(one!=0)
{
printf("%d张一元\n",one);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |