湖南工业大学C语言操作题答案.doc_第1页
湖南工业大学C语言操作题答案.doc_第2页
湖南工业大学C语言操作题答案.doc_第3页
湖南工业大学C语言操作题答案.doc_第4页
湖南工业大学C语言操作题答案.doc_第5页
已阅读5页,还剩20页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

#include #include void main() int arr10=11,4,2,7,3,12,5,34,5,9,i; int s=0; /*found*/ for ( i=0; i10; i+) /*found*/ if (i % 2 = 1) s = s + arri; printf(The result is: %dn, s); 参考答案:#include #include void main() int arr10=11,4,2,7,3,12,5,34,5,9,i; int s=0; /*found*/ for ( i=0;i=9; i+) /*found*/ if (arri % 2 = 1) s = s + arri; printf(The result is: %dn, s); #include stdio.h#include string.hvoid main( ) char s10; unsigned i;/*found*/1; scanf(%s,s);/*found*/for(i=0;2;i+) n=n*10+si-0; printf(n=%ldn,n);参考答案:#include stdio.h#include string.hvoid main( ) char s10; unsigned i;/*found*/ int n=0; scanf(%s,s);/*found*/for(i=0;i5;i+) n=n*10+si-0;printf(n=%ldn,n); #include #define N 3 int fun(int aNN) int min; /*begin*/ /*end*/ return min; void main() void NONO( );/函数声明 int aNN=-1,2,3,4,9,5,7,8,6; int i,j,min; printf(array is:n); for(i=0;iN;i+) for(j=0;jN;j+) printf(%5d,aij); printf(n); min=fun(a); printf(Result is: %dn,min); NONO( ); void NONO( ) FILE *fr,*fw; int i,j,k,m,aNN; fr=fopen(D:exam15400104PROGIN.DAT,r); fw=fopen(D:exam15400104PROGOUT.DAT,w); for(i=1;i=5;i+) for(j=0;jN;j+) for(k=0;kN;k+) fscanf(fr,%d,&ajk); fprintf(fw,%4d,ajk); fprintf(fw,Min = %dn,fun(a); fclose(fr); fclose(fw); 参考答案:#include #define N 3 int fun(int aNN) int min; /*begin*/int i,j; min=a00;for(i=0;iN;i+)for(j=0;jaij)min=aij; /*end*/ return min; void main() void NONO( );/函数声明int aNN=-1,2,3,4,9,5,7,8,6; int i,j,min; printf(array is:n); for(i=0;iN;i+) for(j=0;jN;j+) printf(%5d,aij); printf(n); min=fun(a); printf(Result is: %dn,min); NONO( ); void NONO( ) FILE *fr,*fw; int i,j,k,m,aNN; fr=fopen(D:exam15400104PROGIN.DAT,r); fw=fopen(D:exam15400104PROGOUT.DAT,w); for(i=1;i=5;i+) for(j=0;jN;j+) for(k=0;kN;k+) fscanf(fr,%d,&ajk); fprintf(fw,%4d,ajk); fprintf(fw,Min = %dn,fun(a); fclose(fr); fclose(fw); #include #include void main() int a33=4,4,34,37,3,12,5,6,5,i,j,max,min; max = min = a00; for ( i=0; i3; i+) /*found*/ for ( j=1; j3; j+) if ( max aij ) max = aij; /*found*/ if (min aij) min = aij; printf(The max is: %dn, max); printf(The min is: %dn, min); 参考答案:#include #include void main() int a33=4,4,34,37,3,12,5,6,5,i,j,max,min; max = min = a00; for ( i=0; i3; i+) /*found*/ for ( j=0; j3; j+) if ( max aij) min = aij; printf(The max is: %dn, max); printf(The min is: %dn, min);#include main() int i,g; for(i=1;i1000;i+) /*found*/ g=_(1)_10; /*found*/ if(_(2)_) printf(%4d,i); printf(n); 参考答案:#include main() int i,g; for(i=1;i1000;i+) /*found*/ / g=_(1)_10; g=i%10; /*found*/ / if(_(2)_) if(i=g*g*g) printf(%4d,i); printf(n); #include stdio.h int fun(int m,int n) /*begin*/ /*end*/ void main() void NONO( );/函数声明 int s; int m,n; printf(Enter m n:n); scanf(%d %d,&m,&n); s=fun(m,n); printf(s=%dn,s); NONO( ); void NONO( ) FILE *fr,*fw; int i,x,y; fr=fopen(D:exam15400116PROGIN.DAT,r); fw=fopen(D:exam15400116PROGOUT.DAT,w); for(i=1;i=5;i+) fscanf(fr,%d,%d,&x,&y); fprintf(fw,The Result is :%d*n,fun(x,y); fclose(fr); fclose(fw); 参考答案:#include stdio.h int fun(int m,int n) /*begin*/ int sum=0; for(m;m=n;m+) if(m%7!=0)&(m%5!=0) sum+=m; return sum; /*end*/ void main() void NONO( );/函数声明 int s; int m,n; printf(Enter m n:n); scanf(%d %d,&m,&n); s=fun(m,n); printf(s=%dn,s); NONO( ); void NONO( ) FILE *fr,*fw; int i,x,y; fr=fopen(D:exam15400116PROGIN.DAT,r); fw=fopen(D:exam15400116PROGOUT.DAT,w); for(i=1;i=5;i+) fscanf(fr,%d,%d,&x,&y); fprintf(fw,The Result is :%d*n,fun(x,y); fclose(fr); fclose(fw); #include #include #include void main() int x,y,t,max,min,i,n1,n2; printf(Please enter two numbers:); scanf(%d,%d,&x,&y); if(x y) t = x; x = y; y = t; n1=x; n2=y; t = n2 % n1; /*found*/ while( _(1)_ ) n2 = n1 ; n1 = t ; t = n2 % n1; /*found*/ max = _(2)_ ; min = x * y / max ; printf(max is : %dn,max); printf(min is : %dn,min); 参考答案:#include #include #include void main() int x,y,t,max,min,i,n1,n2; printf(Please enter two numbers:); scanf(%d,%d,&x,&y); if(x y) t = x; x = y; y = t; n1=x; n2=y; t = n2 % n1; /*found*/ /while( _(1)_ )while(t!=0) n2 = n1 ; n1 = t ; t = n2 % n1; /*found*/ /max = _(2)_ ;max=n1; min =x*y/max ; printf(max is : %dn,max); printf(min is : %dn,min); #include #include #include void main() int a12=2,3,5,7,8,9,10,11,12,13,15,17,i,j,k,s; /*found*/ _(1)_; for ( i=0; i12; i+) k=(int)sqrt(ai); for ( j=2;j k ) /*found*/ s=s+_(2)_; printf(Sum is: %dn,s); 参考答案:#include #include #include void main() int a12=2,3,5,7,8,9,10,11,12,13,15,17,i,j,k,s; /*found*/ /_(1)_; s=0; for ( i=0; i12; i+) k=(int)sqrt(ai); for ( j=2;j k ) /*found*/s=s+_(2)_;s=s+ai;printf(Sum is: %dn,s); #include #include #include #include void main() int score,t; printf(Please enter a score:); do scanf(%d,&score); while(score100); t=score/10; /*found*/ switch(score) case 10: case 9:printf(优秀!n);break; case 8:printf(良好!n);break; case 7:printf(中等!n);break; case 6:printf(及格!n);break; /*found*/ else :printf(不及格!n); 参考答案: #include #include #include #include void main() int score,t; printf(Please enter a score:); do scanf(%d,&score); while(score100); t=score/10; /*found*/ switch(t)/修改处 case 10: case 9:printf(优秀!n);break; case 8:printf(良好!n);break; case 7:printf(中等!n);break; case 6:printf(及格!n);break; /*found*/ default :printf(不及格!n);/修改处 #include #define M 100 void main() int a,b,i; a=0;b=0; /*found*/ for(i=1;_(1)_;i+=2) a+=i; /*found*/ _(2)_; printf(sum of evens is %dn,b); printf(sum of odds is %dn,a); 参考答案:#include #define M 100 void main() int a,b,i; a=0;b=0; /*found*/ / for(i=1;_(1)_;i+=2) for(i=1;iM;i+=2) a+=i; /*found*/ / _(2)_; b=5050-a; printf(sum of evens is %dn,b); printf(sum of odds is %dn,a); #include#includeintspace,other;voidfun(charstr)/*begin*/*end*/voidmain()voidNONO();/函数声明charstr80;printf(Inputstring:n);gets(str);fun(str);printf(空格:%d,非空格:%dn,space,other);NONO();voidNONO()FILE*fr,*fw;inti;chars80;fr=fopen(D:exam999999PROGIN.DAT,r);fw=fopen(D:exam999999PROGOUT.DAT,w);for(i=1;i=5;i+)fscanf(fr,%s,s);fun(s);fprintf(fw,空格:%d,非空格:%dn,space,other);fclose(fr);fclose(fw);参考答案: #include #include int space,other;void fun(char str) /*begin*/int i,space=0,other=0;for(i=0;stri!=0;i+)if(stri= )space+;else other+;printf(空格数为%d,space);printf(非空格数为%d,other); /*end*/ void main()void NONO( ); /函数声明char str80;printf(Input string:n);gets(str);fun(str);printf(空格:%d,非空格:%dn,space,other);NONO();void NONO( ) FILE *fr,*fw; int i; char s80; fr=fopen(D:exam999999PROGIN.DAT,r); fw=fopen(D:exam999999PROGOUT.DAT,w); for(i=1;i=5;i+) fscanf(fr,%s,s); fun(s); fprintf(fw,空格:%d,非空格:%dn,space,other); fclose(fr); fclose(fw); 参考答案:#include / 改错 #include int arrmax( int arr33) int i,j,max; max=arr00; /*found*/ for ( i=0; i3; i+) / 此处将1改为0,并且去掉等号 for ( j=0; j3; j+) if (max arrij) max = arrij; return (max); void main() int a33=4,4,34,7,3,12,5,6,5,i,j; /*found*/ printf(The max is: %dn,arrmax(a); /将arrmax(a00)改为arrmax(a) 参考答案:#define M 10 #include void main( ) int i,a100,t; /clrscr(); for(i=0;iM;i+) /*found*/ ai=i+1; /*found*/ for(i=0;iM/2;i+) aM-i-1=ai;for(i=0;iM;i+) printf(%5d,ai); printf(n); 参考答案:#include #include int fun(int m) /*begin*/int a1,a2,a3,s;a1=m/100;a2=m%100/10;a3=m%10;s=a1+a2+a3;return(s); /*end*/ void main() int m,s; /clrscr(); printf(Enter m :n); scanf(%d,&m); s=fun(m);printf(Result is:%dn,s); 参考答案:#include / 改错 #include main() int a10=10,4,2,7,3,12,5,34,5,9,i,s; / clrscr(); s = 0; /*found*/ for ( i=0; i10; i+) / 去掉等号 if (ai % 2 = 0) /*found*/ s = s + ai; / 将i改aiprintf(The result is: %dn, s); 参考答案:#include / 填空 #include void main( ) 02 int num,k; /clrscr() ; /*found*/ k=0; / 给k赋值 printf(Please enter a number:) ; scanf(%d,&num) ; do /*found*/ k=k+num%10 ; / num%10可求出num的各位 num/=10; while(num) ; printf(n%dn,k) ; 参考答案:#include / 改错 #include #include #include void main() int i,j,x,p; /clrscr(); x=1; /*found*/ j=12; while(j1) / 去掉等号 p=(x+1)*2; /*found*/ x=p; j-; printf(total is %dn,p); 参考答案:#include stdio.h / 改错 void main() long int f20=1,1; int i;/clrscr(); /*found*/ f0=1;f1=1; /赋初值 for(i=0;i20;i+) fi+2=fi+fi+1; / 保证前面两个数要输出,所以要这样改 /*found*/ if(i%5=0) printf(n); / i%5=0保证一行5个数输出 printf(%8ld,fi); printf(n); 参考答案:#include stdio.h / 编辑 #include math.h #include stdlib.h double fun(int n) /*begin*/double y=1.0;int i;for(i=2;i=n;i+)y+=1.0/(i*i);return (y); /*end*/ void main() double s; int n; /clrscr(); printf(Enter s:n); scanf(%d,&n); s=fun(n); printf(s= %.3fn,s); 参考答案:#include 填空 #include #include main() int m,n,i,t; long int s=0; /clrscr(); scanf(%d,%d,&m,&n); if( mn ) t=m; m=n; n=t; /*found*/ for (i=m;i=n;i+) if ( i%3=0 & i%7=0 ) s += i; /*found*/ printf(Sum is : %ldn,s ); 参考答案:#include 填空 void main() long s, t, sl=1; int d; /clrscr(); printf(nPlease enter s:); scanf(%ld, &s); t = 0; while ( s 0) d = s%10; /*found*/ if (d%2=0) / 判断余数 t=d * sl + t; sl *= 10; /*found*/ s =s/10; /遇到奇数退出循环后的处理 printf(The result is: %ldn, t); 参考答案:#include stdio.h / 填空#include string.h void main() char s10; int i; long int n; /clrscr(); /*found*/ n=0; / 赋初值 scanf(%s,s); for(i=0;istrlen(s);i+) /*found*/ n=n*10+si-0; / 将字符串转换成整数的方法 printf(n=%ldn,n); 参考答案:#include / 填空 #include double average( int arr , int n ) int k=0,i; double s; s = 0; for ( i=0 ;in; i+) /*found*/ if (arri % 2 =1) / 是恒等号 s = s + arri; k+; return (s/k) ; void main() int a12=10,4,2,7,3,12,5,34,5,9,21,18; double s;/ clrscr(); /*found*/ s = average(a,12); printf(The result is: %.2fn, s); 参考答案:#include #include #include void main() int a10=2,3,5,7,8,9,10,11,12,13,i,j,k,count; / clrscr(); count = 0; for ( i=0; i10; i+) k=sqrt(ai); for ( j=2; jk) count+; /*found*/printf(prime number(s) is(are): %dn,count);#include stdio.h double fun( int n ) double c

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论