版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
本答案仅供参考(请不要随意更改)A类数学表达式(1—12)(N)1、ttinclude<conio.h>#include<stdio.h>floatfun(intm,intn){floattl=l,t2=l,t3=l,i;for(i=l;i<=m;i++)tl*=i;for(i=l;i〈=n;i++)t2*=i;for(i=l;i<=m-n;i++)t3*=i;returntl/(t2*t3);}main()(printf("P二%f\n”,fun(12,8));}2#include<conio.h>#include<math.h>#include<stdio.h>floatfun()floatxl=0.0,xO;xO=xl;xl=cos(xO);while(fabs(xO-xl)>=0.000001){xO=xl;xl=cos(xO);)returnxl;)main(){printf(,,Root=%f\n,,,fun());)3#include<conio.h>#include<stdio.h>doublefun(intn)(doublef0=0,f1=1,fn;fn=fO+fl;while(fn<=n){fO=f1;fl=fn;fn=fO+fl;}returnfn;main() /・主函数・/printf(线f\n”,fun(1000));ttinclude<conio.h>#include<stdio.h>voidfun(float*sn,intn)(floati,t=l;*sn=0;for(i=0;i〈=n;i++){*sn+=t/(2*i+l);t=-t;main()/・主函数・/intn=ll;floats;fun(&s,n);printf〈s=%fn=%d\n,s,n);ttinclude<conio.h>ttinclude<math.h>#include<stdio.h>doublefun(intm){doubles=0,i;for(i=l;i<=m;i++)s+=log(i);returnsqrt(s);main()(printf("%f\n”,fun(20));)6^include<conio.h>^include<stdio.h>#include<math.h>doublefun(doublex,intn){doubles=x+l,i,t=l;for(i=2;i〈=n;i++)t*=i;s+=pow(x,i)/t;}returns;main(){printf("%f\n”,fun(0.3,10));}7#include<stdio.h>#include<math.h>doublefun(intn){doubles=0,i;for(i=l;i〈=n;i++)s+=l.0/(i*(i+l));returns;main()(printf("r”,fun(10));}8#include<stdio.h>#include<math.h>doublefun(doubleeps){doubles=0,t=l,i,m=l;for(i=l;t/m>=eps;i++)|s+=t/m;t=t*i;m=m*(2*i+l);}return2*s;}main(){doublex;printf("Inputeps:");scanf("%lf",&x);printf("\neps=%lf,PI=%lf\n",x,fun(x));}9#include<stdio.h>#include<math.h>doublefun(doublex){doublei,t=l,m=l,s=0;for(i=l;fabs(m/t)>=0.000001;i++)s=s+m/t;m*=(〇.5+1-i)*x;t=t*i;}returns;)main(){doublex,s;printf("Inputx:");scanf&x);s=fun(x);printf("s=%f\n,s);10#include<stdio.h>doublefun(intn)(doubles=0,t=0,i;for(i=l;i<=n;i++)(t+=i;s+=l/t;)returns;}main(){intn;doubles;voidNONO();printf(/z\nPleaseenterN:");scanf("%d",&n);s=fun(n);printf("theresultis:%f\n",s);NONO();IvoidNONO(){/・本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。*/FILE*fp,*wf;inti,n;doubles;fp=fopen("K:\\K15\\24000108\\in.dat","r");wf=fopen("K:\\K15\\24000108\\out.dat","w");for(i=0;i<10;i++){fscanf(fp,r%d",&n);s=fun(n);fprintf(wf,"%f\n",s);)fclose(fp);fclose(wf);}11#include<stdio.h>doublefun(intn)(doublet,sn=l.0;inti,j;for(i=l;i<=n;i++)t=l.0;for(j=l;j<=i;j++)t*=j;sn+=l.0/1;)returnsn;voidmain(){intn;doubles;FILE*out;printf("\nlnputn:");scanf("%d",&n);s=fun(n);printf("s=%f\n",s);out=fopen("out.dat","w");fprintf(out,"%f\n",fun(15));fclose(out);)7/12#include<math.h>#include<stdio.h>doublefun(doublex[10])doublexl=0.0,s=0.0;inti;for(i=0;i<10;i++)xl=xl+x[i];xl=xl/10; /・求10个数的平均值・/for(i=0;i<10;i++)s=s+(x[i]-xl)*(x[i]-xl);returnsqrt(s/10); /・求10个数的方差・/voidmain()doubles,x[10]={95.0,89.0,76.0,65.0,88.0,72.0,85.0,81.0,90.0,56.0};inti;printf("\nTheoriginaldatais:\n");for(i=0;i<10;i++)printf("%6.1f",x[i]);printf("\n\n");s=fun(x);printf("s=%f\n\n",s);}B类最大值和最小值(1—5)ttinclude<stdlib.h>#include<stdio.h>voidfun(inta[],intn,int*max,int*d){inti;d=0;*max=a[0];for(i=0;i<n;i++)if(a[i]>a[*d])|d=i;max=a[*d];main(){inti,x[20],max,index,n=10;randomize();for(i=0;i<n;i++){x[i]=rand()%50;printf("%4d",x[i]);}printf('\n");fun(x,n,&max,&index);printf(Max=%5d,Index二%4d\n”,max,index);)2#include<stdio.h>doublefun(doublea[],intn){doublesum=O,max,min;inti;max=min=a[0];for(i=0;i<n;i++)sum=sum+a[i];if(max<a[i])max=a[i];if(min>a[i])min=a[i];sum=sum-max-min;return(sum/(n-2));main(){doubleb[10],r; inti;printf("输入10个分数放入b数组中:");for(i=0;i<10;i++) scanf("%lf',&b[i]);printf("输入的10个分数是:り;for(i=0;i<10;i++)printf("%4.11f",b[i]);printf("\n");r=fun(b,10);printf("去掉最高分和最低分后的平均分:%f\n",r);)ttinclude<conio.h>ttinclude<stdio.h>ftdefineM3^defineN4voidfun(inttt[M][N],intpp[N])(inti,j;for(j=0;jくN;j++)(Pp[j]=tt[O][j];for(i=l;i<M;i++)if(tt[i][j]<pp[j])pp[j]=tt[i][j];main(){intt[M][N]={{22,45,56,30},{19,33,45,38},(20,22,66,40}};intp[N],i,j,k;printf("Theoriginaldatais:\n");for(i=0;i<M;i++){for(j=0;jくN;j++)printf("%6d”,t[i][j]);printf('\n");fun(t,p);printf('\nTheresultis:\n");for(k=0;k<N;k++)printf("%4d",p[k]);printf('\n〃);)#include<conio.h>#include<stdio.h>intfun(int*s,intt,int*k){inti;*k=0;for(i=l;i<t;i++)if(s[i]>s[*k])*k=i;main()(inta[10]={876,675,896,101,301,401,980,431,451,777},clrscr();fun(a,10,&k);printf("%d,%d\n”,k,a[k])5#include<stdio.h>#defineM4intfun(inta[][M]){inti,j,max=a[0][0];for(i=0;i<2;i++)for(j=0;j<M;j++)if(maxくa[i][j])max=a[i][j];returnmax;main(){intarr[2][M]={5,8,3,45,76,-4,12,82};voidNONO();printf("max=%d\n",fun(arr));NONO();C类二维数组行列下标(1—8)1#include<conio.h>#include<stdio.h>voidfun(inta[3][3],intb[3][3]){inti,j;for(i=0;i<3;i++)for(j=0;j<3;j++)b[i][j]=a[i][j]+a[j][i];}main(){inta[3H3]={{1,2,3},{4,5,6},{7,8,9}},t[3][3];inti,j;fun(a,t);for(i=0;i<3;i++){for(j=0;j<3;j++)printf("%7d",t[i][j]);printf('\n");ttinclude<stdio.h>^include<conio.h>^include<stdlib.h>^defineN5intfun(inta[][N],intm)(inti,j;for(i=0;i<N;i++)for(j=i;jくN;j++)a[i]mainO{inta[N][N],m,i,j;printf(〃*****Thearray*****\n");for(i=0;i<N;i++){for(j=0;jくN;j++){a[i][ホrand()%20;printf("%4d”,a[i][j]);}printf('\n");)dom=rand()%10;while(m>=3);printf("m=%4d\n”,m);fun(a,m);printf("THERESULT\n");for(i=0;i<N;i++){for(j=0;j<N;j++)printf("%4d",a[i][j]);printf("\n");#include<stdio.h>#include<conio.h>intfun(intarray[3]⑶)(intt,i,j;for(i=0;i<2;i++)for(j=l;j<3;j++)(t=array[i][j];array[i][j]=array[j][i];array[j][i]=t;)main()(inti,j;intarray[3][3]={{100,200,300},{400,500,600),{700,800,900}};for(i=0;i<3;i++){ford=0;j<3;j++)printf("%7d",array[i][j]);printf("\n");}fun(array);printf("Convertedarray:\n");for(i=0;i<3;i++){ for(j=0;j<3;j++)printf("%7d",array[i][j]);printf("\n");}}4#include<stdio.h>#include<conio.h>#include<stdlib.h>#defineN5doublefun(intw[][N]){inti,j;doublesum=0;for(j=0;j<N;j++)sum+=w[0][j]+w[N-l][j];for(i=l;i<N-l;i++)sum+=w[i][0]+w[i][N-l];returnsum;voidmain()(inta[N][N]={0,1,2,7,9,1,9,7,4,5,2,3,8,3,1,4,5,6,8,2,5,9,1,4,1};inti,j;doubles;printf("*****Thearray*");for(i=0;i<N;i++){for(j=O;j<N;j++){printf("%4d”,也皿);}printf("\n");)s=fun(a);printf("*****THERESULT*****\n");printf("Thesumis:%lf\n",s);)5.ttinclude<stdio.h>voidfun(int(*s)[10],int*b,int*n,intmm,intnn)inti,j;*n=0;for(i=0;i<mm;i++)for(j=0;jくnn;j++)b[(*n)++]=s[i][j];main(){intw[10][10]={{33,33,33,33},{44,44,44,44},{55,55,55,55}},i,j;inta[100]={0},n=0;printf(/zThematrix:\n,z);for(i=0;i<3;i++){for(j=0;jく4;j++)printf("%3d",w[i][<);printf(〃、n〃);}fun(w,a,&n,3,4);printf("TheAarray:\n");for(i=0;i<n;i++)printf("%3d",a[i]);printf("\n\n");#include<stdio.h>voidfun(ints[][10],intb[],int*n,intmm,intnn)/*以下代码仅供参考・/inti,j,np=0; /*np用作b数组下标・/for(i=0;i<nn;i++)for(j=0;j<mm;j++)b[np++]=s[j][i];*n=np;)main(){ intw[10][10]={{33,33,33,33},{44,44,44,44},{55,55,55,55}},i,jinta[100]={〇},n=O;printf(/zThematrix:\n,z);for(i=O;i<3;i++){for(j=0;j<4;j++)printf(/,%3d,/,w[i][j]);printf('\n");)fun(w,a,&n,3,4);printf("TheAarray:\n");for(i=0;i<n;i++)printf("%3d",a[i]);printf("\n\n");#include<stdio.h>#include<stdlib.h>^defineN5voidfun(inta[][N]){inti,j;for(i=0;i<N;i++)for(j=0;j<=i;j++)a[i][j]=0;main()voidN0N0();inta[N][N],i,j;printf(''*****Thearray*****\n");for(i=0;i<N;i++){for(j=0;j<N;j++){a[i][j]=rand()%10;printf("%4d",a[i][j]);}printf('\n");)fun(a);printf("THERESULT\n");for(i=0;i<N;i++){for(j=0;j<N;j++)printf("%4d",a[i][j]);printf("\n");)N0N0();}voidN0N0(){/・本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。*/FILE*rf,*wf;inti,j,a[5][5];rf=fopen("K:\\K15\\24000108\\in.dat","r");wf=fopen("K:\\K15\\24000108\\out.dat","w");for(i=0;i<5;i++)for(j=0;j<5;j++)fscanf(rf,"%d",&a[i][j]);fun(a);for(i=0;i<5;i++){for(j=0;j<5;j++)fprintf(wf,"%4d",a[i][j]);fprintf(wf,"\n");}fclose(rf);fclose(wf);)8ttinclude<stdio.h>ttinclude<stdlib.h>^defineN5voidfun(inta[][N],intn)(inti,j;for(i=0;i<N;i++)for(j=0;j<=i;j++)a[i][j]*=n;}main()(voidN0N0();inta[N][N],n,i,j;printf(''*****Thearray*****\n〃);for(i=0;i<N;i++){for(j=0;j<N;j++){a[i][j]=rand()%10;printf("%4d",a[i][j]);}printf('\n");}don=rand()%10;while(n>=3);printf(z,n=%4d\n”,n);fun(a,n);printf("*****THERESULT*****\n");for(i=0;i<N;i++){for(j=0;j<N;j++)printf(线>4d”,a[i][j]);printf("\n〃);}N0N0();}voidN0N0(){/・本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。・/FILE*rf,*wf;inti,j,n,a[5][5];rf=fopen("K:\\K15\\24000103\\in.daJ,〃r〃);wf=fopen('K:\\K15\\24000103\\out.dat","w");for(i=0;i<5;i++)for(j=0;j<5;j++)fscanf(rf,"%d”,&a[i][j]);fscanf(rf,"%d",&n);fun(a,n);for(i=0;i<5;i++){for(j=0;j<5;j++)fprintf(wf,"%4d",a[i][j]);fprintf(wf,"\n");)fclose(rf);fclose(wf);D类素数(1—3)ttinclude<conio.h>ttinclude<stdio.h>voidfun(intm,int*k,intxxロ){inti,j;*k=0;for(i=2;iくm;i++)(for(j=2;jくi;j++)if(i%j=0)break;if(j<i)xx[(*k)++]=i;}main(){intm,n,zz[100];printf(〃、nPleaseenteranintegernumberbetween10and100:");scanf("%d",&n);fun(n,&m,zz);printf("\n\nThereare%dnon-primenumberslessthan%d:,m,n);for(n=0;n<m;n++)printf("\n%4d\n",zz[n]);将大于形参m且紧靠m的k个素数存入xx数组中。voidfun(intm,intk,intxx[])(/*以下代码仅供参考*/inti,j=l,t=m+1;while(j<=k)(/・以下完成判断素数,并存放到数组xx中・/for(i=2;i<t;i++)if(t%i—0)break;if(i>=t){xx[j-l]=t;j++;}t++;)main()(intm,xx[100],k,i;scanf("%d,%d",&m,&k);fun(m,k,xx);for(i=0;i<k;i++)printf("%3d”,xx[i]);ttinclude<math.h>ttinclude<stdio.h>doublefun(intn)(inti,j;doubles=0;for(i=3;i<n;i++){for(j=2;j<i;j++)if(i%j=O)break;if(j>=i)s+=sqrt(i);)returns;}main(){intn;doublesum;printf('\n\nlnputn:");scanf("%d",&n);sum=fun(n);printf('\n\nsum=%f\n\n",sum);E数学其它(1-17)#include<conio.h>#include<stdio.h>voidfun(inta,intb,long*c){*c=a/10*1000+a%10*10+b/10+b%10*100;}main(){inta,b;longc;printfInputa,b:");scanf("%d%d”,&a,&b);fun(a,b,&c);printf[Theresultis:%ld\nz,,c);}2#include<conio.h>ttinclude<stdio.h>#defineM200intaa[1000];voidfun(int*n)*n=0;for(i=l;i<1000;i++)if((i%7==0||i%ll==0)&&i%77!=0)aa[(*n)++]=i;main(){intn,k;fun(&n);for(k=0;k<n;k++)if((k+l)%10==0)printf('\n");elseprintf("%5d”,aa[k]);)3#include<conio.h>#include<stdio.h>unsignedfun(unsignedw){longt=10;while(w/t!=0)t*=10;returnw%(t/10);}main(){unsignedx;printf(,zEnteraunsignedintegernumber:");scanf&x);printf(z,Theoriginaldatais:%u\n〃,x);if(x<10)printf("Dataerror!");elseprintf("Theresult:%u\n",fun(x));#include<stdio.h>#include<math.h>doublefun(doublex[9]){inti;doubles=0;for(i=l;i<9;i++)s=s+sqrt((x[iT]+x[i])/2);returns;}main(){doubles,a[9]={12.0,34.0,4.0,23.0,34.0,45.0,18.0,3.0,11.0};inti;printf("\nTheoriginaldatais:\n");for(i=0;i<9;i++)printf("%6.If",a[i]);printf("\n\n");s=fun(a);printf("s=%f\n\n",s);ttinclude<stdio.h>ttinclude<conio.h>defineN20fun(int*a,intn,int*odd,int*even){inti;odd=0;even=0;for(i=0;i<n;i++)if(a[i]%2!=0)odd=*odd+a[i];else*even+=a[i];main(){inta[N]={l,9,2,3,11,6},i,n=6,odd,even;printf("Theoriginaldatais:\n");for(i=0;i<n;i++)printf("%5d”,*(a+i));printf('\n\n");fun(a,n,&odd,&even);printf("Thesumofoddnumbers:%d\n",odd);printf("Thesumofevennumbers:%d\n",even);#include<stdio.h>#include<stdlib.h>#defineN15intfun(int*s,intx)(inti;for(i=0;i<N;i++)if(x==s[i])returni;return-1;)main(){inta[N]={29,13,5,22,10,9,3,18,22,25,14,15,2,7,27},i,x,index;printf("a数组中的数据:\n");for(i=0;i<N;i++)printf("%4d",a[i]);printf("\n");printf("给x输入.查找的数:り;scanf("%d",&x);index=fun(a,x);printf("index=%d\n",index);ttinclude<conio.h>ttinclude<stdio.h>ttinclude<string.h>intfun(intscore[],intm,intbelow[])(floatave=0;inti,j=0;for(i=0;i<m;i++)ave+=score[i];ave/=m;for(i=0;i<m;i++)if(score[i]<ave)below[j++]=score[i];returnj;}main(){inti,n,below[9];intscore[9]={10,20,30,40,50,60,70,80,90);n=fun(score,9,below);printf('\nBelowtheaveragescoreare:");for(i=0;iくn;i++)printf("%d",below[i]);)8#include<conio.h>#include<stdio.h>voidfun(intx,intpp[],int*n)(inti;*n=0;for(i=l;i〈=x;i=i+2)if(x%i==0)pp[(*n)++]=i;main(){intx,aa[1000],n,i;printf('\nPleaseenteranintegernumber:\n");scanf("%d",&x);fun(x,aa,&n);for(i=0;i<n;i++)printf(,z%d”,aa[i]);printf(〃、n");)9#include<conio.h>^include<stdio.h>intfun(intx){inti;i=x*x;if(i%10==x|Ii%100~x)return1;elsereturn0;y;inty;printf(*\nPleaseenteraintegernumbers:");scanf(〃%d〃,&x);if(x>100IIx<0){printf("dataerror!\n");exit(0);}y=fun(x);if(y)printf("%dYES\n",x);elseprintf("%dNO!\n",x);)10#include<conio.h>#include<stdio.h>ttdefineM20doubleAcc(intk,doubleddロ){doubles=0;inti;for(i=0;i<k;i++)s+=(dd[i]-(long)dd[i]);returns;}main(){inti,m;doublex,tt[M];printf("\nPleaseenternumberofnumbers:");scanf("%d",&m);printf(/z\nPleaseenter%ddecimalnumbers:\nz,,m);for(i=0;i<m;i++){scanf("%lf",&x);tt[i]=x;}printf〈\nThesumoftheirdecimalpartis:%lf\n/z,Acc(m,tt));11#include<conio.h>#include<stdio.h>#include<math.h>ttdefineM20doublePdt(intn,doubleppロ){doubles=0;inti;for(i=0;i<n;i++)s+=(long)pp[i];returns;main()inti,m;doublett[M];printf(〃\nPleaseenternumberofnumbers:〃);scanf&m);printf('\nPleaseenter%ddecimalnumbers:",m);for(i=0;i<m;i++)scanf("断f”,&tt[i]);printf("\nTheproductoftheirintegerpartis:%lf.",Pdt(m,tt));12#include<stdio.h>#defineN80voidfun(int*w,intp,intn){inti,j,t;for(i=0;i<p;i++)(t=w[0];for(j=l;j<n;j++)w[j-l]=w[j];w[n-l]=t;}main(){inta[N>{l,2,3,4,5,6,7,8,9,10,11,12,13,14,15);inti,p,n=15;printf(^Theoriginaldata:\n,z);for(i=0;i<n;i++)printf("%3d",a[i]);printf('\n\nEnterp:");scanf("%d",&p);fun(a,p,n);printf('\nThedataaftermoving:\n,z);for(i=0;i<n;i++)printf("%3d",a[i]);printf('\n\n");)13#include<stdio.h>ttdefineN80intfun(inta[],intn)(inti,j=0;for(i=l;i<n;i++)if(a[i-l]<a[i])a[j++]=a[i-l];a[j++]=a[n-l];returnj;)main(){inta[N]={2,2,2,3,4,4,5,6,6,6,6,7,7,8,9,9,10,10,10,10},i,n=20Tprintf("Theoriginaldata:\n");for(i=0;i<n;i++)printf("%3d",a[i]);n=fun(a,n);printf('\n\nThedataafterdeleted:\n");for(i=0;i<n;i++)printf("%3d",a[i]);printf("ヽn'n");14#include<stdio.h>ttdefine N 50^define M 11voidfun(int*a,int*b){inti,j;for(i=0;iくM;i++)b[i]=0;for(i=0;iくN;i++)if(a[i]>=100)b[10]++;elseb[a[i]/10]++;doublernd(){statict=29,c=217,m=1024,r=0;r=(r*t+c)%m;return((double)r/m);}mainO{intage[N],i,d[M];for(i=0;i<N;i++)age[i]=(int)(115*rnd());printf("Theoriginaldata:\n");for(i=0;i<N;i++)printf((i+l)%10==0?"%4d\n":"%4d”,age[i]);printf("\n\n");fun(age,d);for(i=0;i<10;i++)printf(,/%4d %4d:%4d\n”,i*10,i*10+9,d[iB;printf("Over100:%4d\n”,d[10]);)15^include<math.h>ttinclude<stdio.h>doublefun(intn){inti;longs=0;for(i=0;i<n;i++)if(i%3=0&&i%7==0)s+=i;returnsqrt(s);}main(){printf("s=%f\n”,fun(1000));}16^include<stdio.h>floatfun(floath)h=h+0.005;h=(int)(h*100)/100.0;returnh;main(){floata;voidNONO();printf("Entera:");scanf("%f",&a);printf("Theoriginaldatais: ");printf("%f\n\n",a);printf("Theresult:%f\n",fun(a));N0N0();voidNONO(){/・请在此函数内打开文件,输入测试数据,调用fun函数,输出数据,关闭文件。*/inti;floata;FILE*rf,*wf;rf=fopen("K:\\K15\\24000108\\in.dat","r");wf=fopen("K:\\K15\\24000108\\out.dat","w");for(i=0;i<20;i++){fscanf(rf,"%f",&a);fprintf(wf,"%f\n",fun(a));)fclose(rf);fclose(wf);17#include<stdio.h>floatfun(float*a,(inti;floatav=0.0;for(i=0;i<n;i++)av=av+a[i];return(av/n);intn)/・求分数的总和・//・返回平均值・/main(){floatscore[30]={90.5,72,80,61.5,55},aver;aver=fun(score,5);printf("\nAveragescoreis:%5.2f\n",aver);F类字符串大小转换(1—2)#include<stdio.h>#defineN80voidfun(char*s)(inti;for(i=0;s[i]!='\0';i++)if(i%2!=0)if(s[i]>='A'&&s[i]<'Z')s[i]=s[i]+l+32;elseif(s[i]=='Z')s[i]='z";main(){chars[N];printf("Enterastring:");scanf("%s",s);fun(s);printf("Theresult:%s",s);)2#include<stdio.h>#include<string.h>voidfun(char*ss)(inti;for(i=0;ss[i];i++)if(i%2)if(ss[i]>=,a,&&ss[i]<=,z,)ss[i]-=32;)voidmain(void)chartt[51];printf("\nPleaseenterancharacterstringwithin50characters:\n");gets(tt);printf("\n\nAfterchanging,thestring\n\"%s\"",tt);fun(tt);printf("\nbecomes\n\"%s\"",tt);G类字符串或字母出现的次数(1-4)#include<conio.h>#include<stdio.h>#defineM81intfun(char*ss,charc)(inti,n=O;for(i=0;ss[i]!=,\0,;i++)if(ss[i]==c)n++;returnn;)main(){chara[M],ch;printf("\nPleaseenterastring:");gets(a);printf("\nPleaseenterachar:");ch=getchar();printf("\nThenumberofthecharis:%d\n",fun(a,ch));#include<stdio.h>#include<string.h>#include<conio.h>intfun(char*str,char*substr)(inti,m=O;for(i=0;str[i+l]!='\O';i-H-)if(str[i]==substr[0]&&str[i+l]==substr[l])m++;returnm;)main()(charstr[81],substr[3];intn;printf("输入主字符串:");gets(str);printf("输入子字符串:");gets(substr);puts(str);puts(substr);n=fun(str,substr);printf("n=%d\n",n);#include<conio.h>#include<stdio.h>voidfun(char*tt,intpp[])(inti;for(i=0;i<26;i++)Pp[i]=O;for(i=0;tt[i]!='\0';i++)pp[tt[i]-'a']++;)main(){charaa[1000];intbb[26],k,n;printf("\nPleaseenteracharstring;");scanf("%s",aa);fun(aa,bb);for(k=0;k<26;k++)printf("%d",bb[k]);printf("\n");4#include<stdio.h>voidN0N0();intfun(char*s)(intn=0;while(*s)if(*s>=’〇'&&*s<='9')n++;s++;)returnn;main(){char*s="2def35adh253kjsdf7/kj8655x”;printf("%s\n",s);printf("%d\n”,fun(s));NONO();}voidNONO(){/・本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。*/FILE*fp,*wf;inti;chars[256];fp=fopen('K:\\K15\\24000103\\in.daピ,"r");wf=fopen('K:\\K15\\24000103\\out.dat","w");for(i=0;i<10;i++){fgets(s,255,fp);fprintf(wf,"%d\n”,fun(s));)fclose(fp);fclose(wf);H类字符串的删除及移动(1—14)#include<stdio.h>#include<string.h>#include<conio.h>#include<stdlib.h>voidfun(char*s,chart[])(inti=0;for(;*s!='\0';s++) /・找出ASCII值为奇数的字符依次存入数组t中・/if(*s%2==l)t[i++]=*s;; /・在字符串的末尾加上串结束符・/)voidmain()(chars[100],t[100];system("CLS");printf("\nPleaseenterstringS:");scanf("%s",s);fun(s,t);printf("\nTheresultis:%s\n",t);2(1)#include<stdio.h>ttinclude<string.h>voidfun(char*s,chart[])inti,k=0;for(i=0;s[i];i++)if(i%2[=0&&s[i]%2!=0)t[k++]=s[i];t[k]=O;main(){chars[100],t[100];voidNONO();printf('\nPleaseenterstringS:");scanf1'%s,s);fun(s,t);printf('\nTheresultis:%s\n〃,t);NONO();2(2)voidfun(char*s,chart[])inti,k=0;for(i=0;s[i];i++)if(s[i]%2=0)t[k++]=s[i];t[k]=O;main()chars[100],t[100];printf('\nPleaseenterstring>:);scanf(〃%s〃,s);fun(s,t);printf('\nTheresultis:%s\n〃,t);#include<stdio.h>voidfun(char*a)(inti,k=O;for(i=0;a[i];i++)if(a[i]!='*')a[k++]=a[i];a[k]=O;main(){chars
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
评论
0/150
提交评论