习题第三章#includestdio.h#includemath.hintmain(){intd,p;doubler,a,m;scanf(%d%d%lf,&d,&p,&r);a=(p/(p-d*r));m=log(a)/log(1+r);if(p0&&d0){if(d=m*p)printf(%.1f,m);elseprintf(God);}elseprintf(0.0);return0;}勾股数#includestdio.hintmain(){inta,b,c,n;scanf(%d,&n);for(a=1;a=n;a++){for(b=1;b=n;b++){for(c=1;c=n;c++){if(c*c==a*a+b*b){if(a=b){printf(%d%d%d\n,a,b,c);}}}}}return0;}第四章计算分段函数值#includestdio.hintmain(){floatx,y;scanf(%f,&x);if(x1)y=x;elseif(x=1&&x10)y=2*x-1;elseif(x=10)y=3*x-11;printf(%.2f,y);return0;}找出三个数中最大的数#includestdio.hintmain(){inta,b,c,max;scanf(%d%d%d,&a,&b,&c);max=ab?a:b;if(cmax)max=c;printf(%d,max);return0;}10844成绩等级评分#includestdio.hintmain(){intx;scanf(%d,&x);if(x=0&&x=100){switch(x/10){case10:case9:printf(A);break;case8:printf(B);break;case7:printf(C);break;case6:printf(D);break;default:printf(E);break;}}elseprintf(error);return0;}前续和后续字符#includestdio.hintmain(){charx;x=getchar();switch(x){case'0':printf(first);printf(%c,x+1);break;case'9':printf(%c,x-1);printf(last);break;case'1':case'2':case'3':case'4':case'5':case'6':case'7':case'8':printf(%c,x-1);printf(%c,x+1);break;default:printf(error);break;}return0;}20秒后的时间#includestdio.h#includestdlib.hintmain(){inth,m,s;scanf(%d:%d:%d,&h,&m,&s);s=s+20;if(s59){s=s%60;m++;if(m59){m=m%60;h++;if(h23)h=0;}}printf(%02d:%02d:%02d\n,h,m,s);return0;}分期还款#includestdio.h#includemath.hintmain(){intd,p;doubler,a,m;scanf(%d%d%lf,&d,&p,&r);a=(p/(p-d*r));m=log(a)/log(1+r);if(p0&&d0){if(d=m*p)printf(%.1f,m);elseprintf(God);}elseprintf(0.0);return0;}第五章字母分类统计#includestdio.h#includestdlib.hintmain(){charch;inta=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0;while((ch=getchar())!='\n'){if(ch=127&&ch=123)a++;elseif(ch=97&&ch=122)b++;elseif(ch=96&&ch=91)c++;elseif(ch=90&&ch=65)d++;elseif(ch=58&&ch=64)e++;elseif(ch=48&&ch=57)f++;elseif(ch=33&&ch=47)g++;elseif(ch==32)h++;elsei++;}printf(%d%d%d%d,d+b,f,h,a+c+e+g+i);}水仙花数#includestdio.hintmain(){intn,a,b,c;for(n=100;n1000;n++){a=n/100;b=(n%100)/10;c=n%10;if(n==a*a*a+b*b*b+c*c*c){printf(%d\n,n);}}return0;}计算数列和#includestdio.hintmain(){inta=1,n,i,sum=0;scanf(%d,&n);for(i=1;i=n;i++){sum=sum+a;a=a+2;}printf(%d,sum);return0;}自由落体#includestdio.hintmain(){inti,n;doubleh=100.0,s=0.0,c=100.0;scanf(%d,&n);{s=s+c;h=h/2;c=2*h;}printf(%.3lf,s);printf(%.3lf,h);return0;}迭代法求平方根#includestdio.h#includemath.hintmain(){floatx1,x2,a;x2=1;scanf(%f,&a);x1=a/x2;while(fabs(x1-x2)=1e-5){x1=x2;x2=0.5*(x1+a/x1);}printf(%.4f\n,x2);return0;}打印三角形#includestdio.h#includestdlib.h#includemath.hintmain(){intn,k,i,j;scanf(%d,&n);for(i=0;i2*n-1;i++){k=abs(n-1-i);for(j=0;jk;j++){printf();}for(j=0;jn-k;j++){printf(*);}printf(\n);}return0;}勾股数#includestdio.hintmain(){inta,b,c,n;scanf(%d,&n);for(a=1;a=n;a++){for(b=1;b=n;b++){for(c=1;c=n;c++){if(c*c==a*a+b*b){if(a=b){printf(%d%d%d\n,a,b,c);}}}}}return0;}第六章18052插入数据intx,i,t;scanf(%d,&x);a[15]=x;for(i=15;i0;i--){if(a[i]a[i-1]){t=a[i];a[i]=a[i-1];a[i-1]=t;}}大于平均分#includestdio.hintmain(){inta[10];inti,sum=0,average,count;for(i=0;i10;i++){scanf(%d,&a[i]);}for(i=0;i10;i++){sum=sum+a[i];}average=sum/10;count=0;for(i=0;i10;i++){if(a[i]average)count++;}printf(%d,count);return0;}输出不同的数据#includestdio.hintmain(){inta[20];inti,t,p=0;for(i=0;i10;i++){scanf(%d,&a[i]);}for(i=0;i10;i++){for(t=0;ti;t++)if(a[t]==a[i])break;if(t==i)printf(%d\n,a[i]);}}主对角线上的元素之和#includestdio.hintmain(){inta[3][4],i,j,sum=0;for(i=0;i3;++i){for(j=0;j4;++j){scanf(%d,&a[i][j]);}}for(i=0;i3;++i){sum+=a[i][i];}printf(%d\n,sum);return0;}1051鞍点#includestdio.hintmain(){inti,j,k,t=0,flag=0,m=0,n=0,a[3][4],max,min;for(i=0;i3;i++){for(j=0;j4;j++){scanf(%d,&a[i][j]);}}for(i=0;i3;i++){max=a[i][0];for(j=0;j4;j++){if(maxa[i][j]){max=a[i][j];m=i;n=j;}}for(k=0;k3;k++){min=a[m][n];if(mina[k][n])flag=1;}if(flag==0){t=1;printf(%d\n,a[m][n]);}flag=0;}if(t==0)printf(NO);return0;}ASCII码值之和的差#includestdio.h#includestring.hintmain(){chars1[80];chars2[80];inti,sum1=0,sum2=0;gets(s1);gets(s2);for(i=0;istrlen(s1);i++){sum1+=s1[i];}for(i=0;istrlen(s2);i++){sum2+=s2[i];}printf(%d,sum1-sum2);return0;}第七章所有数字之和#includestdio.hintsum(intn){if(n10)returnn;intres=0;res=(n%10)+sum(n/10);returnres;}main(){intn;scanf(%d,&n);printf(%d,sum(n));}元音字母#includestdio.h#includestdlib.hvoidyuan(char*s,char*s2){inti,k=0;charc;for(i=0;*(s+i)!='\0';i++){c=*(s+i);switch(c){case'a':case'e':case'i':case'o':case'u':case'A':case'E':case'I':case'O':case'U':*(s2+k)=c;k++;break;default:break;}}*(s2+k)='\0';}intmain(){charstr[81],str2[81];gets(str);yuan(str,str2);printf(%s,str2);}字符统计#includestdio.h#includestring.h#includemath.hintnL=0,nN=0;intstatistics(char*s){intnS=0,a;while(*s!='\0'){a=*s;if(a=='')nS++;else{if(a='1'&&a='9')nN++;elseif((a='a'&&a='z')||a='A'&&a='Z')nL++;}s++;}returnnS;}intmain(){chars[81];intnS;gets(s);nS=statistics(s);printf(%d%d%d\n,nL,nN,nS);return0;}选择排序#includestdio.hintsort(inta[],intn){inti,j,k,tmp;for(i=0;in-1;i++){k=i;for(j=i+1;jn;j++)if(a[j]a[k])k=j;tmp=a[k];a[