} }
void main()
{ float a[5][6]; int i,j; float *b[5];
for(i=0; i<5; i++) for(j=0;j<6;j++) scanf(\ for(i=0;i<5;i++) b[i]=a[i]; f(b,5,6);
for(i=0;i<5;i++) { for(j=0;j<6;j++) printf(\ \putchar('\\n');}
} 方法二:
#include
void f(float *p, int m, int n) { int i,j; float max; for(i=0;i for(j=1;j void main() { float a[5][6]; int i,j; for(i=0;i<5;i++) for(j=0;j<6;j++) scanf(\ f(a[0],5,6) for(i=0; i<5; i++) { for(j=0;j<6;j++) printf(\ } 13. 编制函数,在字符串数组中查找与另一字符串相等的字符串,函数返回值为该字符串的地址或NULL(当查找不到时)。 解答: #include char *str(char *str[], int n, char *s) { int i; for(i=0; i void main() { char *s[5]={\ printf(\ } 14. 下列程序中,函数find_data在已从小到大排序好的数组中寻找指定数data,采用二分查找算法,找到则返回该数组元素地址,找不到返回NULL。请填空将程序补充完整。 #include float* find_data(float *a,int n,float data) 31 { int low,mid,high ; low=0; high=n-1; while(low<=high) { mid=(low+high)/2; if(a[mid]>data) high=mid-1; else if(a[mid] return NULL ; } void main() { float b[10],*p,data; for(int i=0;i<10;i++) scanf(\要求输入数据值从小到大 */ scanf(\输入待查找的数据 */ p=find_data(b,10,data); if(p) printf(\ else printf(\查找不到%f\\n\ } 67?2(x2?x?sinx)dx??3(log10x2?x?3)dx15. 程序填空,将求下列两个定积分之和的程序补充完整。 其中,求定积分的函数采用用梯形公式n(main中对应的实参取50)等份积分区间。 #include float f1(float),f2(float); float fs( float a,float b,int n, float(*f)(float)) { float s=0,x=a,h=(b-a)/n; int i; for(i=1;i<=n;i++) { s+=((*f)(x)+(*f)(x+h))*h/2; x+=h; } return s ; } void main() { float y; y=fs(2,6,50,f1)+fs(3,7,50,f2); printf(\ } float f1(float x) { return x*x+x*sin(x); } float f2(float x) { return log10(x*x)-x+3 ;} 32 习 题 九 1. 构造一个表示通讯录中每个“记录”的数据类型,声明该类型的标识符。 解答:struct person{ char name[9];int pho;}; ⒉ 编程,先输入n,再输入通讯录中若干个人的记录到结构体数组中,按电话号码的升序对结构体数组排序后输出。 解答: #include struct person{ char name[9]; int pho; }; void main() { struct person *p,temp; int n,i,j,k; scanf(\ for(i=0;i k=i; for(j=i+1;j for(i=0;i 解答: #include struct person{ char name[9]; int pho; }; void sort(struct person *p,int n) { struct person temp; int i,j,k; for(i=0;i k=i; for(j=i+1;j void main() { struct person *p,temp; int n,i,j,k; scanf(\p=(struct person*) malloc(n*sizeof(struct person)); for(i=0;i for(i=0;i 解答: #include struct node { char x; struct node* t; }; void main() { struct node *h=NULL,*p1,*p2; char ch; 33 while((ch=getchar())!='.') { p2=(struct node*) malloc(sizeof(struct node)); p2->x=ch; if(h==NULL) h=p1=p2; else { p1->t=p2; p1=p2;} } p2->t=NULL; p1=h; while(p1!=NULL){ if(isalpha(p1->x))putchar(p1->x); p1=p1->t; } putchar('\\n'); } 5.阅读下列程序,写出输出结果。 程序⑴ #include { struct T1{ char c[4],*s;} s1={\ struct T2{ char *cp; T1 ss1;} s2={\ printf(\ printf(\ printf(\ printf(\ } 输出结果为 a,d abc,def ghi,mno hi,no 程序⑵ #include { struct info { int data; info *pn; } info *base,*p; base=NULL; for(int i=0;i<10;i++) { p=(inf*) malloc(sizeof(struct info)); p->data=i+1; p->pn=base; base=p; } p=base; while(p!=NULL) { printf(\ } printf (\ } 输出结果为 10 9 8 7 6 5 4 3 2 1 6.下列函数用于将节点类型为ntab的链表中某个结点(数据成员data与形参num匹配)删除,填空将函数补充完整。 解答: struct ntab* del_node(struct ntab *h, int num) { struct ntab *p1,*p2; if(h==NULL) { printf(\ p1=h; while(num!=p1->data && p1->next!=NULL) { p2=p1; p1=p1->next; } if(num==p1->data) 34 if(p1==h) { h=p1->next; free(p1); } else { p2->next=p1->next; delete p1; } else printf(\ return h; } 7.下列函数用于在节点类型为ltab的非空链表中插入一个节点(由形参指针变量p0指向),链表按照节点数据成员no的升序排列,填空将函数补充完整。 解答: struct ltab* insert(struct ltab* head,struct ltab* stud) { struct ltab *p0,*p1,*p2; p1=head;p0=stud; while((p0->no>p1->no)&&( p1->next!=NULL)){ p2=p1; p1=p1->next; } if(p0->no<=p1->no) if(head==p1) { p0->next=head; head=p0; } else { p2->next=p0; po->next=p1; } else { p1->next=p0; p0->next=NULL; } return (head); } 习 题 十 1. 计算下列表达式的值。 ⑴ 5&7 ⑵ -12&6 ⑶ 7|8 ⑷ -12||32 ⑸ (x=13)^9 ⑹ 15/2^1 ⑺ ~-15 ⑻ ~15/3 ⑼ 7<<2 ⑽ -9<<2 ⑾ (x=13)>>3 ⑿ -9>>3 解答:⑴ 5 ⑵ -5 ⑶ 15 ⑷ 1 ⑸ 4 ⑹ 6 ⑺ 14 ⑻ -5 ⑼ 28 ⑽ -36 ⑾ 1 ⑿ -2 2. 变量a、b均被声明为short类型,分别写出执行下列语句后a、b的值。 ⑴ a=4;b=5;a&b; ⑵ a=-4;b=a|6; ⑶ a=3;b=a<<2; ⑷ a=-15;b=~a>>2 解答:⑴ a=4,b=5 ⑵ a=-4,b==2 ⑶ a=3,b=12 ⑷ a=-15,b=3 3. 阅读下列程序,写出运行时输入 6 8 8 4 12 -5 23 -12 ^z 的输出结果。 #include void sub1(short *x,short *y) { *x=*x^*y; *y=*x^*y; *x=*x^*y; } void main() { short a,b; while(scanf(\ sub1(&a,&b); printf(\ } } 解答:交换 a、b 的值。 4. 编程,输入一个int类型数据后,输出该数的机内码。 解答: #include { int a,i; char b[33]={'\\0'}; 35