1!+2!+....n! 用c语言怎么写,力求用较为简单的语言

如题所述

第1个回答  2011-11-02
C语言程序 #include "graphics。h" #include "stdio。h" void huatu(l,w,h) { setcolor(BLUE);setlinestyle(0,0,3); line(360-w。2,720+h-w。2,310+w。2,220+h-w。2); line(520-w。2,120,550-w。2,820+h-w。2); line(710+w。2,720,140+w。2,820+h-w。2); line(120-w。2,370-l。2,320+w。2,040-l。2); line(240-w。2,810-l。2,300-w。2,650+l。2); line(400-w。2,100+l。2,350+w。2,710+l。2); line(680+w。2,100-l。2,410+w。2,340+l。2); setcolor(YELLOW);setlinestyle(6,0,3); line(750-w。1,510-l。2,350-w。2,420+l。2); line(650+w。7,520-l。2,620+w。6,310+l。2); line(210+w。30,520-l。2,780+w。00,810+l。2); line(240-w。70,250-l。2,460-w。60,710+l。2); line(440-l。2,220-w。4,840+l。2,620-w。6); line(340-l。2,720+w。0,320+l。2,720+w。1); setlinestyle(0,0,8);setcolor(BLUE); line(850-l。2,620-w。2,080+l。2,820-w。2); line(470-l。2,120+h-w。2,350+l。2,420+h-w。2); line(160-l。2,620-w。2,400-l。2,320+h-w。2); line(780+l。2,020-w。2,300+l。2,120+h-w。2); setcolor(WHITE);setlinestyle(0,0,3); line(300-w。2,720+h-w。2,570+w。2,820+h-w。2); line(010-w。2,220,070-w。2,220+h-w。2); line(280+w。2,620,530+w。2,020+h-w。2); circle(500,020,w。5); arc(860,720,0,470,w。2); circle(630,420-w。2。84,w。30); setcolor(GREEN);setbkcolor(BLACK); setlinestyle(0,0,8); rectangle(30,20,430,860); setlinestyle(0,0,3); rectangle(20,20,820,860); setcolor(RED);setlinestyle(2,0,4); line(00,320,200,120); line(200,30,260,680); line(300,520,280,220); line(110,10,300,580); line(30,260,250,170); line(310,270,720,770); setcolor(GREEN);setlinestyle(0,0,8); line(600,270,700,540); line(800,030,320,410); line(100,200,220,200); line(200,170,320,180); line(100,380,620,660); line(540,100,240,150); settextstyle(DEFAULT_FONT,HORIZ_DIR,2); outtextxy(860,230,"Computer Program Course Design"); outtextxy(620,230," Name"); outtextxy(820,720,"Number"); outtextxy(560,820,"gaoyuan"); outtextxy(340,770,"0500047368"); } main() { int driver,mode,l,w,h; float k; driver=VGA,mode=2; initgraph(&driver,&mode,""""); setbkcolor(BLACK); printf("enter l(20<l<320) w(80<W<10) h(60<h<60)"); scanf("%d%d%d",&l,&w,&h); huatu(l,w,h); printf("k"); scanf("%f",&k); h=h*k,w=w*k,l=l*k; clearviewport(); huatu(l,w,h); getch(); }ftn
第2个回答  2011-11-02
#include "stdio.h"
void main()
{
int n,i;
long sum=0,total=1;
printf("输入n的值:\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
total*=i;
sum+=total;
}
if(n>3)
printf("1!+2!+...+%d!=%ld",n,sum);
else if(n==3)
printf("1!+2!+3!=%ld",sum);
else if(n==2)
printf("1!+2!=%ld",sum);
else
printf("1!=%ld",sum);
}
第3个回答  2011-11-02
#include <stdio.h>
void main()
{
char k;
while(k!='n')
{
long count_num(0);
long num[500];
printf("%s\n","please enter number:");
int n(0);
scanf("%d",&n);

num[0]=1;
count_num=num[0];
for (int i=1;i<n;i++)
{
num[i]=num[i-1]*(i+1);
count_num+=num[i];
}
printf("%d",count_num);
printf("%s\n","是否退出?y/n");
}
}
第4个回答  2011-11-02
用两层嵌套的循环语句,外层求1!+2!+....n!,内层求n!。本回答被提问者采纳
第5个回答  2011-11-02
#include <stdio.h>

int main()
{
int n,it,temp,sum;
while(scanf("%d",&n)==1)
{
sum = 0;
temp = 1;
it = 1;
while(it<=n)
{
temp *= it;
sum += temp;
it++;
}
printf("answer is %d\n",sum);
}
}
相似回答