文档详情

南航C语言课后习题09答案.pdf

发布:2017-05-27约字共14页下载文档
文本预览下载声明
习题9 答案 1. 解答 1: #include stdio.h void swap( int *pa, int *pb, int *pc) { int t; if(*pa*pb) { t=*pa; *pa=*pb; *pb=t; } if(*pa*pc) { t=*pa; *pa=*pc; *pc=t; } if(*pb*pc) { t=*pb; *pb=*pc; *pc=t; } } main( ) { int a, b, c; scanf(%d%d%d, a, b, c); swap(a,b,c); printf(%d\t%d\t%d\n, a, b, c); } 解答2 : #include stdio.h void swap2( int *m, int *n) { int t; t=*m; *m=*n; *n=t; } void swap( int *pa, int *pb, int *pc) { if(*pa*pb) swap2(pa, pb); if(*pa*pc) swap2(pa, pc); if(*pb*pc) swap2(pb, pc); } main( ) { int a, b, c; scanf(%d%d%d, a, b, c); swap(a,b,c); printf(%d\t%d\t%d\n, a, b, c); } 2 . 解答: #include stdio.h void stat(char *str, int *letter, int *digit, int *space, int *other) { char c; for( ; *str; str++) { c=*str; if((a=cc=z)||(A=cc=Z)) (*letter)++; else if(c ) (*space)++; else if(0=c c=9) (*digit)++; else (*other)++; } } main( ) { char str[100]; int letter=0, digit=0, space=0, other=0; /* 变量letter 用于统计字母的个数 */ /* 变量digit 用于统计数字字符的个数 */ /* 变量space 用于统计空格的个数 */ /* 变量other 用于统计其他字符的个数 */ gets(str); stat(str, letter, digit, space, other); printf(letter=%d\n, let
显示全部
相似文档