2、){k=str[i];str[i]=str[j-l-i];str[j-l-i]=k;}}2.输入10个数给一维数组a[10],再按逆序重新存放并输出。#includevoidmain(){inti,x,a[10];for(i=0;i<10;i卄)scanf(”%d”,&a[i]);for(i=0;i<5;i++){x=a[i];a[i]=a[9-i];a[9-i]=x;}for(i=0;i<10;i++)printf(,,%dn,a[i]);三、级数求和1•按公式片+矿尹..+才十算e的值,误差小于Z#include#defineP0.0001void
3、main(){floatx=1,k=1;inti=1;do{k=k*i;x=x+1/k;i++;}while(1/k>p);printfC'e的值=%f”,x);}3!5!7!9!2.计算数列1-丄+…的和至某项的绝对值小于le・5时为止(该项不累加)。#includc#includevoidmain(){floatsum=1,t=1,i=3;do{t=-t*i*(i-1);sum+=1/t;i+=2;}while(fabs(l/t)>=le-5);printfV^uin=%f,sum);}2.输入1个实数给x和一个正整数给n,计算并输出下式s
4、in(x)的值。要求定义和调用函数fun(x,n)计算兀",类型是double。=1-—+—-引5!7!#includedoublefun(floatx,intn){inti;doublet=1;for(i=1;i<=n;i++)returnt;voidmain(){intj.n;doublex,t=l,y=1;scanf(,'%lf%d",&x,&n);for0=3;j<=n;j=j+2){t=-t*j*(j-l);y=y+fun(x,j)/t;}printf(ny=%f'*,y);2.输入1个实数给x和一个正整数给m计算并输出下式的值。要求定义和调用函数fact
5、(k)计算k的阶乘,定义和调用函数mypow(x,k)计算x",类型是double。#includeintfact(intn){inti,t=1;fbr(i=1;i<=n;i++)t=t*i;returnt;}doublemypow(floatx,intn){inti;doublet=1;for(i=1;i<=n;i++)returnt;voidmain(){inti,n;doublex,sum=0;printf(”输入x和n:n);scanf(n%lf%dn,&x,&n);fbr(i=l;i<=n;i++)sum=sum+mypow(x,i)/fact(i);}pri
6、ntf("sum=%f”,sum);四、因子和1.输出6〜10000之间的亲密数对。【说明】若a、b是亲密数对,则a的因子和等于b、b的因子和等于a且a不等于bo#includcvoidmain(){inti,a,b,c;fbr(a=6;a<=10000;a++){b=l;for(i=2;i<=a/2;i++)if(a%i=0)b+=i;c=1;for(i=2;i<=b/2;i++)if(b%i=0)c+=i;if(a==c&&a!=b)printf(n%d%d",a,b);c*C:VPROGRA^IVC-FREE"1・5te>pUntit...■冋x
7、2
8、20284▲284220—1184121012101184262029242924262050205564556450206232636863686232Pressanykeytocontinue■•▼HI12.找出500以内的所有完数,并输出其因子。【说明】一个数恰好等于它的因子之和,这个数称为完数,如6=1+2+3。程序1要求定义和调用函数f(k)计算k的因子之和。//includeintf(intn){int