浙江省c语言考程序设计题.docVIP

  • 71
  • 0
  • 约 16页
  • 2016-10-18 发布于广东
  • 举报
浙江省c语言考程序设计题

程序设计题 1. #includestdio.h #includemath.h void main() { FILE *p; int x,y,x1,y1; float z,z1; x1=0; y1=0; z1=10*cos(x1-4)+5*sin(y1-2); for(x=0;x=10;x++) for(y=0;y=10;y++){ z=10*cos(x-4)+5*sin(y-2); if(z1z){ x1=x; y1=y; z1=z; } } p=fopen(design.dat,w); fprintf(p,%d,%d,x1,y1); fclose(p); } 2. 设计程序:计算27的小于1.00001的2n次方根(27的2n-2次方根不小于1.00001),将n以格式%d写到考生目录中Paper子目录下的新建文件design.dat中。 #include stdio.h #include math.h void main() { FILE *p; float x=27; int n=0; p=fopen(design.dat,w); do{ n++; }while(pow(x,1.0/(2*n))=1.00001 || pow(x,1.0/(2*n-2))1.00001); fprintf(p,%d,n); fclose(p); } 3. 设计程序:计算多项式a0+a1*x+a2*x*x+a3*x*x*x+...的值,并将其值以格式%f写到考生目录中Paper子目录下的新建文件design.dat中。 #include stdio.h #include math.h void main() { FILE *p; int i; float x=1.279,t=1,y=0; float a[10]={1.1,3.2,-2.5,5.67,3.42,-4.5,2.54,5.6,0.97,4.65}; for(i=0;i10;i++){ y+=a[i]*t; t*=x; } p=fopen(design.dat,w); fprintf(p,%f,y); fclose(p); } 4. 设计程序:在正整数中找出1个最小的、被3、5、7、9除,余数分别为1、3、5、7的数,将该数以格式%d写到考生目录中Paper子目录下的新建文件design.dat中。 #include stdio.h #include math.h void main() { FILE *p; int n=1; while(n%3!=1 || n%5!=3 || n%7!=5 || n%9!=7) n++; p=fopen(design.dat,w); fprintf(p,%d,n); fclose(p); } 5. 设计程序:在6至5000内找出所有的亲密数对,并将每对亲密数用fprintf(p,%6d,%6d\n,a,b); 语句写到考生目录中Paper子目录下的新建文件design.dat中。 说明:若a、b为1对亲密数,则a的因子和等于b、b的因子和等于a、且a不等于b。如:220、284是1对亲密数,284、220也是1对亲密数。 #include stdio.h void main() { FILE *p; int a,b,c,k; p=fopen(design.dat,w); for(a=6;a=5000;a++){ c=1; for(k=2;ka;k++) if(a%k==0) c+=k; for(b=6;b=5000;b++){ if(c==b a!=b){ c=1; for(k=2;kb;k++) if(b%k==0) c+=k; if(c==a) fprintf(p,%6d,%6d\n,a,b); } } } fclose(p); } 6. 设计程序:将字符串s中的所有字符按ASCII值从小到大重新排序后,将排序后的字符串写入到考生目录中Paper子目录下的新建文件design.dat中。 #include stdio.h #include string.h void main() { FILE *p; char *s=634,.%@\\w|SQ2,c; int i,j,k,n=strlen(s); p=fopen(design.dat,w); for(i=0;in-1;i++){ k=i; for(j=i+1;jn;j++) if(s[k]s[j]) k=j; if(k!=i){ c=s[i]; s[i]=s[k]; s[k]=c; } } for(i=

文档评论(0)

1亿VIP精品文档

相关文档