资源描述:
《C程序设计教程与实验(吉顺如陶恂)实验8答案.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、.Sy8-1#includevoidmain(){inti;staticinta[8]={10,5,4,0,12,18,20,46};voidjhmaxmin();printf("Originalarray:");for(i=0;i<8;i++)printf("%5d",a[i]);printf("/n");jhmaxmin(a,8);printf("Arrayafterswapwingmaxandmin:");for(i=0;i<8;i++)printf("%5d",a[i]);printf("");}voidjhmaxmin(intp[],intn){intt
2、,*max,*min,*end,*q;end=p+n;max=min=p;for(q=p+1;q*max)max=q;if(*q<*min)min=q;}t=*max;*max=*min;*min=t;}Sy8-2#includeintlen(chars[]){char*p=s;while(*p!=' ')p++;returnp-s;}main(){chars[80];gets(s);printf(""%s"include%dcharacters.",s,len(s));}Word资料.Sy8-3#include#i
3、ncludevoidmain(){inti,a[26];charch,str[80],*p=str;gets(str);for(i=0;i<26;i++)a[i]=0;while(*p!=' '){ch=*(p++);ch=ch>'A'&&ch<='Z'?ch+'a'-'A':ch;if('a'4、
5、'A'<=ch<='Z')a[ch-'a']++;}for(i=0;i<26;i++)printf("%2c",'a'+i);printf("出现的次数为:");for(i=0;i<26;i++)printf("%2d",a[i]);printf("")
6、;}Sy8-4#includemain(){inta[8],*p;inti,j,t,k;p=a;printf("Inputthenumbers:");for(i=0;i<8;i++)scanf("%d",p+i);t=*p;for(i=0;i<8;i++){for(j=i;j<8;j++)if(j==i
7、
8、*(p+j)#in
9、cludechnum(char*p);voidmain(){chars[6];intn;gets(s);if(*s=='-')n=-chnum(s+1);elsen=chnum(s);printf("%d",n);}chnum(char*p){intnum=0,k,len,j;len=strlen(p);for(;*p!=' ';p++){k=*p-'0';j=(--len);while(j-->0){k=k*10;}num=num+k;}return(num);}Sy8-6#includemain(){inti,k=0;chara[80],b[80
10、],*p;p=a;gets(p);Word资料.while(*p){for(i=1;p[i-1]!=' ';p++,k++,i++){if(k%4==0){b[k]='';k++;}b[k]=*p;}}b[k]=' ';puts(b);}Sy8-7#includevoidmain(){chars[30],*p=s;inta,*q=&a,i;gets(s);*q=0;for(;*p!=' ';p++)if(*p>='0'&&*p<='9')*q=(*q)*10+(*p-'0');printf("字符中的数字为:%d",a);}Sy8-8#include11、.h>zlrjm(char*Z){char*A=Z;while(*A!=' '){if('a'<=*A<='z'
12、
13、'A'<=*A<='Z'){*A=*A+3;if(*A>'Z'&&*A<'a'
14、
15、*A>'z')*A=*A-26;}++A;}}zlrJm(char*Z){char*A=Z;Word资料.while(*A!=' '){if('a'<=*A<='z'
16、
17、'A'<=*A<='Z'){