编程题16-20.docVIP

  • 4
  • 0
  • 约1万字
  • 约 31页
  • 2017-12-22 发布于河南
  • 举报
编程题16-20

编程题16-20 16 题目: 请编写一个函数float fun(double h),函数的功能是对变量h中的值保留2位小数,并对第三位进行四舍五入(规定h中的值为正数)。 例如:若h值为8.32433,则函数返回8.32;若h值为8.32533,则函数返回8.33。 注意:部分源程序如fill.c给出。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 #include stdio.h #include conio.h float fun ( float h ) { } main() { float a; clrscr( ); printf ( Enter a: ); scanf ( %f, a ); printf ( The original data is: ); printf ( %f \n\n, a ); printf ( The result : %f\n, fun ( a ) ); } 17 题目: 请编写一个函数fun(char *s),该函数的功能是把字符串中的内容逆置。 例如:字符串中原有的字符串为abcdefg,则调用该函数后,串中的内容为gfedcba。 注意:部分源程序如fill.c给出。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 #include string.h #include conio.h #include stdio.h #define N 81 void fun ( char *s) { } main() { char a[N]; clrscr( ); printf ( Enter a string : ); gets ( a ); printf ( The original string is: ); puts( a ); fun ( a ); printf(\n); printf ( The string after modified : ); puts ( a ); } 18 题目: 编写程序,实现矩阵(3行列)的转置(即行列互换)。 例如,若输入下面的矩阵: 100 200 300 400 500 600 700 800 900 则程序输出: 100 400 700 200 500 800 300 600 900 注意:部分源程序如fill.c给出。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 #include stdio.h #include conio.h int fun(int array[3][3]) { } main() { int i,j; int array[3][3]={{100,200,300}, {400,500,600}, {700,800,900}}; clrscr(); for (i=0;i3;i++) { for(j=0;j3;j++) printf(%7d,array[i][j]); printf(\n); } fun(array); printf(Converted array:\n); for (i=0;i3;i++) { for(j=0;j3;j++) printf(%7d,array[i][j]); printf(\n); } } 19 题目: 编写函数fun,该函数的功能是:从字符串中删除指定的字符。同一字母的大、小写按不同字符处理。 例如:若程序执行时输入字符串为:turbo c and borland c++ 从键盘上输入字符n,则输出后变为:turbo c ad borlad c++ 如果输入的字符在字符串中不存在,则字符串照原样输出。 注意:部分源程序如fill.c给出。 请勿改动主函数main和其他函数中的任何内容,仅在函

文档评论(0)

1亿VIP精品文档

相关文档