2、n=nox;13.ints1=0,s2=0;ch=getchar()ch>=’A’&&ch<=’Z’printf(“%dt%d”,s1,s2);14.#includem,n,jc=1;“%d”,&mn-215.inti,j,k;j=-45;j<=45;j++i*i+j*j+k*k==1989“%d,%d,%d”三、程序分析题141.8522.i=3i=1i=-13.k=84.ABABCDCD5.SUM=24686.7777777555553331四.程序设计题1.解:#includevoidmain(){inti,j,k;for(i
3、=1;i<=9;i++)/*百位数*/for(j=0;j<=9;j++)/*十位数*/for(k=0;k<=9;k++)/*个位数*/if(i*i*i+j*j*j+k*k*k==1099)printf(“各位数字的立方和等于1099的整数是:%d”,i*100+j*10+k);}2.解:#includevoidmain(){inti,t,f1=1,f2=1;printf(“%d,%d,”,f1,f2);for(i=3;i<=20;i++){t=f1+f2;printf(“%d,“,t);/*求出新的数*/f1=f2;f2=t;/*对f1和f2更新*/}
4、}3.解:#include#include#defineeps1e-5voidmain(){ints=1;/*s为符号变量*/floatitem=1.0,pi=0,n=1.0;/*item存放每一项值,n存放每一项分母*/while(fabs(item)>=eps){pi=pi+item;/*pi存放级数累加和*/n=n+2;s=-s;/*改变分母值和符号变反*/item=s/n;/*求下一项*/}pi=4*pi;14printf(“pi=%8.6f”,pi);}3.解一:#includevoidmain(){inti,j
5、,n;longintt=1,sum=0;/*t存放每项阶乘值,sum存放累加和*/printf(“inputn:”,&n);scanf(“%d”,&n);for(i=1;i<=n;i++){t=1;for(j=1;j<=i;j++)/*求i!值*/t=t*j;sum=sum+t;/*累加*/}printf(“n!=%ld”,sum);}解二:按提示:n!=n*(n-1)!以下程序效率高。#includevoidmain(){inti,n;longintt=1,sum=0;/*t存放每项阶乘值,sum存放累加和*/printf(“inputn:”,&n);s
6、canf(“%d”,&n);for(i=1;i<=n;i++){t=t*i;/*前一项(i-1)!乘i,得i!值*/sum=sum+t;/*累加*/}printf(“n!=%ld”,sum);}5.解:#includevoidmain(){intt=1,i=1;doublee=1,x=1;while(x>1e-6){t=t*i;x=1.0/t;e=e+x;i++;}printf(“e=%f”,e);}6.解:#includevoidmain(){intr=1;doublex=1,y=0;while(x>1e-6){14x=1.0/(r
7、*r+1);y=y+x;r++;}printf(“y=%f”,y);}7.解:#includevoidmain(){inti;for(i=0x20;i<=0x6f;i++)printf(“十进制数值=%d,对应字符=%c”,i,i);}8.解:#includevoidmain(){inti,a,b,c;for(a=6;a<=10000;a++){b=c=1;for(i=2;i<=a/2;i++)if(a%i==0)b=b+i;for(i=2;i<=b/2;i++)if(b