第8章实验.docVIP

  • 333
  • 0
  • 约4.58千字
  • 约 9页
  • 2017-12-22 发布于河南
  • 举报
第8章实验

第8章实验 程序功能:函数strcat(str1,st2)实现将字符串str2拼接到字符串str1后面的功能。 /****** s8-1.c ******/ #include stdio.h char *strcat1(char *str1,char *str2) { char *t=str1; while (_____1____ ) str1++; while ( _____2_____ ); return(t); } main() { char s1[80],s2[80],*s3; gets(s1); gets(s2); s3=strcat1(s1,s2); printf(%s\n ,s3); } 程序功能:依次取出字符串中所有小写字母以形成新的字符串,并取代原字符串。 /****** s8-2.c ******/ #include stdio.h void fun(char *s) { int i=0; char *p=s; while ( ____1____ ) { if (*p=’a’ *p=’z’) { s[i]=*p; ____2____; } p++; } s[i]= ____3____ ; } main() { char str[80]; gets(str); fun(str); printf(\n the string of changing is:%s\n,str); } 程序功能:通过指针作函数的参数实现三个数从小到大的排序。 /****** s8-3.c ******/ #include stdio.h void swap (_____1_____ ) { int i; i=*pt1; *pt1=*pt2; *pt2=i; } void exchange (int *q1,int *q2,int *q3) { if ( _____2_____ ) swap(q1,q2); if ( _____3_____ ) swap(q1,q3); if ( _____4_____ ) swap(q2,q3); } main() { int a,b,c; int *p1, *p2, *p3; p1=a; p2=b; p3=c; *p1=24;*p2=93;*p3=15; exchange( _____5_____ ); printf(a=%d,b=%d,c=%d\n ,a,b,c); } 程序功能:以下程序统计命令行第一个参数中出现的字母个数,请调试通过。 /****** s8-4.c ******/ #includestdio.h #includectype.h main(int argc, _____1____) { char *str; int count=0; if(argc2) exit(1); str=______2_____; while(*str) if (isalpha( ____3____ )) count++; printf(\n Letter number is:%d\n ,count); } 改错 程序功能:给定程序中函数 fun 的功能是:将在字符串s中下标为奇数位置上的字符,紧随其后重复出现一次,放在一个新串t中,t中字符按原字符串中字符的顺序排列。(注意0为偶数) 例如:当s中的字符串为:ABCDEF时, 则t中的字符串应为:BBDDFF。 请改正函数fun中的错误,使它能得出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构! /****** s8-5.c ******/ #include conio.h #include stdio.h #include string.h void fun (char *s, char *t) { int i, j, sl; sl = strlen(s); /************found************/ for (i=0, j=0; isl; i+=2) { t[2*j] = s[i]; t[2*j +1] = s[i]; /************found************/ j--; } t[2*j] = \0; } main() { char s[100], t[100]; printf(\nPlease enter string s:); scanf(%s, s); fun(s, t); printf(The result is: %s\n, t); } 程序设计 (1) 请编写函数,对传送过来的三个数选出最大和最小数,并通过形参传回结果。部分源程序如下: /****** s8-6.c ******/ #inclu

文档评论(0)

1亿VIP精品文档

相关文档