欢迎来到天天文库
浏览记录
ID:18470595
大小:49.00 KB
页数:33页
时间:2018-09-18
《[10] 第六次上机作业(国外英语资料)》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、[10]第六次上机作业Thesixthtime,thefunctionofthemachineOneplusonehalf!+...+1/n!Theprogramfillsinanddoesnotchangethestatementsassociatedwiththeinputoutput.Enterapositiveintegerrepeat(02、sumofthefirstntermsofs(keep4decimalplaces).S=1+1/2!+...+1/n!Youwanttodefineandcallthefunctionfact(n)tocomputenfactorial.Example:theparenthesisistheexplanationInput:2(repeat=2)2(n=2)10(n=10)Output:1.50001.7183[6.1]#include"stdio."Voidmain(){Intri,repe3、at;IntI,n;Doubles;Doublefact(intn);Scanf("%d",&repeat);For(ri=1){Scanf("%d",&n);S=0;For(I=1;I<=n;I++)S+=fact(I);Printf("%0.4f",s);}}Doublefact(intn){Intj,t=1;Doublex;For(j=1;j<=n;j++){T*=j;X=1.0/t;}Return(x);}Sowhatisa+aa+aaa+aa?a.Theprogramfillsin4、anddoesnotchangethestatementsassociatedwiththeinputoutput.Enterapositiveintegerrepeat(05、toreturnaa?A(n)a.Forexample,thereturnvalueoffn(3,2)is33.Example:theparenthesisistheexplanationTheinput2(repeat=2)2,3(a=2,n=3)8,5(a=8,n=5)Theoutput246(2+22+222)98760(8+88+888+8888+88888)[6.2](thedefinitionfunctiondoesnotqualifyforthereturnvalue,pendin6、gmodification)#includeVoidmain(){Intri,repeat;IntI,n;Longa,sn.Longa,intn;Scanf("%d",&repeat);For(ri=1){Scanf("%ld%d,");Sn=fn(a,n);Printf("%ld",sn);}}Longa,intn.{Intj,tn;Longsum;Tn=a;Sum=0;For(j=1;j<=n;j++){Thesum+=tn;Tn=10*tn+a;}Return(sum7、);}[revisedprogram]#includeVoidmain(){Intri,repeat;IntI,n;Longa,sn.Longa,intn;Scanf("%d",&repeat);For(ri=1){Scanf("%ld%d,");Sn=0;For(I=1;I<=n;I++)Sn+=fn(a,I);Printf("%ld",sn);}}Longa,intI.{Intj,tn=a,sum=0;For(j=0;j8、rn(sum);}6.3countsthenumberofNumbersinanintegerTheprogramfillsinanddoesnotchangethestatementsassociatedwiththeinputoutput.Enterapositiveintegerrepeat(0
2、sumofthefirstntermsofs(keep4decimalplaces).S=1+1/2!+...+1/n!Youwanttodefineandcallthefunctionfact(n)tocomputenfactorial.Example:theparenthesisistheexplanationInput:2(repeat=2)2(n=2)10(n=10)Output:1.50001.7183[6.1]#include"stdio."Voidmain(){Intri,repe
3、at;IntI,n;Doubles;Doublefact(intn);Scanf("%d",&repeat);For(ri=1){Scanf("%d",&n);S=0;For(I=1;I<=n;I++)S+=fact(I);Printf("%0.4f",s);}}Doublefact(intn){Intj,t=1;Doublex;For(j=1;j<=n;j++){T*=j;X=1.0/t;}Return(x);}Sowhatisa+aa+aaa+aa?a.Theprogramfillsin
4、anddoesnotchangethestatementsassociatedwiththeinputoutput.Enterapositiveintegerrepeat(05、toreturnaa?A(n)a.Forexample,thereturnvalueoffn(3,2)is33.Example:theparenthesisistheexplanationTheinput2(repeat=2)2,3(a=2,n=3)8,5(a=8,n=5)Theoutput246(2+22+222)98760(8+88+888+8888+88888)[6.2](thedefinitionfunctiondoesnotqualifyforthereturnvalue,pendin6、gmodification)#includeVoidmain(){Intri,repeat;IntI,n;Longa,sn.Longa,intn;Scanf("%d",&repeat);For(ri=1){Scanf("%ld%d,");Sn=fn(a,n);Printf("%ld",sn);}}Longa,intn.{Intj,tn;Longsum;Tn=a;Sum=0;For(j=1;j<=n;j++){Thesum+=tn;Tn=10*tn+a;}Return(sum7、);}[revisedprogram]#includeVoidmain(){Intri,repeat;IntI,n;Longa,sn.Longa,intn;Scanf("%d",&repeat);For(ri=1){Scanf("%ld%d,");Sn=0;For(I=1;I<=n;I++)Sn+=fn(a,I);Printf("%ld",sn);}}Longa,intI.{Intj,tn=a,sum=0;For(j=0;j8、rn(sum);}6.3countsthenumberofNumbersinanintegerTheprogramfillsinanddoesnotchangethestatementsassociatedwiththeinputoutput.Enterapositiveintegerrepeat(0
5、toreturnaa?A(n)a.Forexample,thereturnvalueoffn(3,2)is33.Example:theparenthesisistheexplanationTheinput2(repeat=2)2,3(a=2,n=3)8,5(a=8,n=5)Theoutput246(2+22+222)98760(8+88+888+8888+88888)[6.2](thedefinitionfunctiondoesnotqualifyforthereturnvalue,pendin
6、gmodification)#includeVoidmain(){Intri,repeat;IntI,n;Longa,sn.Longa,intn;Scanf("%d",&repeat);For(ri=1){Scanf("%ld%d,");Sn=fn(a,n);Printf("%ld",sn);}}Longa,intn.{Intj,tn;Longsum;Tn=a;Sum=0;For(j=1;j<=n;j++){Thesum+=tn;Tn=10*tn+a;}Return(sum
7、);}[revisedprogram]#includeVoidmain(){Intri,repeat;IntI,n;Longa,sn.Longa,intn;Scanf("%d",&repeat);For(ri=1){Scanf("%ld%d,");Sn=0;For(I=1;I<=n;I++)Sn+=fn(a,I);Printf("%ld",sn);}}Longa,intI.{Intj,tn=a,sum=0;For(j=0;j8、rn(sum);}6.3countsthenumberofNumbersinanintegerTheprogramfillsinanddoesnotchangethestatementsassociatedwiththeinputoutput.Enterapositiveintegerrepeat(0
8、rn(sum);}6.3countsthenumberofNumbersinanintegerTheprogramfillsinanddoesnotchangethestatementsassociatedwiththeinputoutput.Enterapositiveintegerrepeat(0
此文档下载收益归作者所有