添加收藏
 系统管理
 联系方式
  汉南在线考试认证计算机二级

等级考试教材第十四章编程题目答案
作  者:汉南居士
关键字:C语言基础



14.12

#include "stdio.h"
#define N 30
#define M 4

struct stud{
 char num[5],name[10];
 int s[M];
 double ave;
};

void readrec(struct stud *p){
 int i=0;
 double ave_tmp=0.0;
 printf("No:");
 scanf("%s",p->num);
 printf("Name:");
 scanf("%s",p->name);
 while(i<M){
  printf("Couse[%d]:",i+1);
  scanf("%d",&p->s[i]);
  ave_tmp+=p->s[i];
  i++;
 }
 p->ave=ave_tmp/M;
}
void writerec(struct stud *p){
 int i=0;
 printf("\nNo:%5s Name:%10s\n",p->num,p->name);
 while(i<M){
  printf("Course[%d]=%3d ",i+1,p->s[i]);
  i++;
 }
 printf("\nAve=%f",p->ave);
}

 

void main(){
 struct stud pstu[N];
 int i=0;
 while(i<N){
  readrec(&pstu[i]);
  i++;
 }
 i=0;
 while(i<N){
  writerec(&pstu[i]);
  i++;
 }
}

14.13

#include "stdio.h"
#include "stdlib.h"

struct de{
 int data;
 struct de *next;
};
typedef struct de DE;

DE *create_list();
DE *pMax(DE *h);
int findmax(DE *h);

DE *create_list(){
 int c;
 DE *h,*s,*r;
 h=(DE *)malloc(sizeof(DE));
 r=h;
 scanf("%d",&c);
 while(c!=-1){
  s=(DE *)malloc(sizeof(DE));
  s->data=c;
  r->next=s;
  r=s;
  scanf("%d",&c);
 }
 r->next='\0';
 return h;
}

int findmax(DE *h){
 DE *p,*s;
 s=h;
 p=h->next;
 if(p=='\0') {
   printf("list if Null!\n");
   return p->data;
  }
 while(p->next!='\0'){
  if(p->data<s->data) p=p->next;
   else {
    s=p;
    p=p->next;
   }
 }
 return (s->data>p->data)?(s->data):(p->data);
}

DE *pMax(DE *h){
 DE *p,*s;
 s=h;
 p=h->next;
 if(p=='\0') {
   printf("list if Null!\n");
   return p;
  }
 while(p->next!='\0'){
  if(p->data<s->data) p=p->next;
   else {
    s=p;
    p=p->next;
   }
 }
 return (s->data>p->data)?s:p;
}

void main(){
 DE *head,*tmp;
 head=create_list();
 printf("%d\n",findmax(head));
 tmp=pMax(head);
 printf("%d",tmp->data);
}



来源:互联网
阅读:683
日期:2006-3-3

【 双击滚屏 】 【 推荐朋友 】 【 收藏 】 【 打印 】 【 关闭 】 【 字体: 】 
上一篇:第一至三章答案 高等教育出版社《全国计算机等级考试二级教程--C语言程序设计》课后答案
下一篇:等级考试教材第十三章编程题目答案

  >> 相关文章
 
  ·第一至三章答案 高等教育出版社《全国计算机等级考试二级教程--C语言程序设计》课后答案
  ·第四章答案 高等教育出版社《全国计算机等级考试二级教程--C语言程序设计》课后答案

5.12汶川大地震遇难同胞默哀 | 汉南在线总站 | 免费电影 | BT电影下载 | 东莞信息网 | 流行购商城

授权使用:汉南在线 http://hnzx.hzwz.net/
经营许可证:陕ICP备05000109号 Powered by:汉南在线
Copyright (c) 2002-2007 汉南在线. All Rights Reserved .