C语言程序设计第九-十一章习题参考答案
C语言第九章参考答案1.选择题:12345 67890 12ADCDB BCDDC BB2.填空题:(1)指针或者地址(2)110(3)①char *p; ②p=&ch; ③scanf("%c",p); ④*p='a'; ⑤printf("%c",*p);(4)10 (5)0、7 (6)ab (7)abcdcd (8) 7ㄩ1(9)void (*p)(int * ,int*); (10)r+b[k] (11) '\0' 、n++; (12)aegi 3.改错题:(1) 第一处改正:* sub=x-y第二处改正:scanf("%f%f",&x,&y);第三处改正:calc(x,y,&add,&sub);(2)第一处:char swap (char *p1,char*p2)改为void swap (char *p1,char*p2)第二处:strcpy(p,p1)改为strcpy(p,p2)(3)第一处:p1=p1+m改为p1=p1+m-1第二处:*p1=*p2改为*p2=*p1第三处:*p2="\0"改为*p2='\0'(4)第一处:char *fun(char *str,char t)改为char *fun(char *str,char *t)第二处:s=NuLL改为s=NULL;第三处:if(r==p)改为if(*r==*p)(5)第一处:fun(int **b,int n)改为fun(int (*b)[N],int n)第二处:b[j][k]=k*j 改为b[j][k]=(k+1)*(j+1)4编程题(1)/*习题9-4-1 */void move(int array[20],int n,int m) ;main(){ int number[20],n,m,i;printf("How many numbers?"); /*共有多少个数*/scanf("%d",&n);printf("Input %d numbers:\n",n); /*输入n个数*/for(i=0;i<n;i++)scanf("%d",&number[i]);printf("How many place you want to move?"); /*后移多少个位置*/scanf("%d",&m);move(number,n,m); /*调用move函数*/ printf("Now,they are:\n");for(i=0;i<n;i++)printf("%d ",number[i]);}void move(int array[20],int n,int m) /*循环后移函数*/{ int *p,array_end;array_end=*(array+n-1);for(p=array+n-1;p>array;p--)*p=*(p-1);*array=array_end;m--;if(m>0) move(array,n,m); /*递归调用,当循环次数m减至0时,停止调用*/}(2)/*习题9-4-2 */#include<stdio.h>#include<string.h>#define TOTAL 6int mseek(char*str[],char xstr[],int n){ int i;for(i=0; i<n; i++){ if(strcmp(str[i],xstr)==0)return 1;}return 0;}main(){ char*name[TOTAL]={"Lining","Linshan","Tianyuan","Zhangqiang","Haipo","Fangbing"};char xname[20];printf("enter a name:");gets(xname);if(mseek(name,xname,TOTAL))printf("Found!\n");elseprintf("Not found!\n");}(3)/*习题9-4-3 */#include <stdio.h>#include <string.h>void fun(char *str,int num[4]){ int i;for(i=0; i<4; i++) num[i]=0;while(*str!='\0'){ if(*str>='a' && *str<='z' || *str>='A' && *str<='Z')num[0]++;else if(*str==' ')num[1]++;else if(*str>='0' && *str<='9')num[2]++;elsenum[3]++;str++;}}#define N 80main(){ int string[N];int n[4],i;gets(string);fun(string,n);for(i=0; i<4; i++)printf("%d\t",n[i]);}(4)/*习题9-4-4 *//* 调试时,可这样输入数据:*//*11 12 13 14 1521 22 23 24 2531 32 33 34 3541 42 43 44 4551 52 53 54 55 */#include <stdio.h>main(){ int a[5][5],*p,i,j;void change(int *p);printf("Input matrix:\n");for(i=0;i<5;i++) /*输入矩阵*/for(j=0;j<5;j++)scanf("%d",&a[i][j]);p=&a[0][0]; /*使p指向0行0列元素*/ change(p); /*调用函数, 实现交换*/ printf("Now, matrix: \n");for(i=0;i<5;i++) /*输出已交换的矩阵*/{ for(j=0;j<5;j++)printf("%4d",a[i][j]);printf("\n");}}void change(int *p) /*交换函数*/{ int i,j,temp;int *pmax,*pmin;pmax=p;pmin=p;for(i=0;i<5;i++) /*找最大值和最小值的地址,并赋给pmax,pmin*/ for(j=0;j<5;j++){ if(*pmax<*(p+5*i+j)) pmax=p+5*i+j;if(*pmin>*(p+5*i+j)) pmin=p+5*i+j;}temp=*(p+12); /*将最大值换给中心元素*/*(p+12)=*pmax;*pmax=temp;temp=*p; /*将最小值换给左上角元素*/*p=*pmin;*pmin=temp;pmin=p+1;for(i=0;i<5;i++) /*找第二最小值的地址赋给pmin*/ for(j=0;j<5;j++)if(((p+5*i+j)!=p)&&(*pmin>*(p+5*i+j))) pmin=p+5*i+j;temp=*pmin; /*将第二最小值换给右上角元素*/*pmin=*(p+4);*(p+4)=temp;pmin=p+1;for(i=0;i<5;i++) /*找第三最小值的地址赋给pmin*/ for(j=0;j<5;j++)if(((p+5*i+j)!=(p+4))&&((p+5*i+j)!=p)&&(*pmin>*(p+5*i+j)))pmin=p+5*i+j; /*将第三最小值换给左下角元素*/ temp=*pmin;*pmin=*(p+20);*(p+20)=temp;pmin=p+1;for(i=0;i<5;i++) /*找第四最小值的地址赋给pmin*/ for(j=0;j<5;j++)if(((p+5*i+j)!=p)&&((p+5*i+j)!=(p+4))&&((p+5*i+j)!=(p+20))&&(*pmin>*(p+5*i+j))) pmin=p+5*i+j;temp=*pmin; /*将第四最小值换给右下角元素*/*pmin=*(p+24);*(p+24)=temp;}(5)/*习题9-4-5 *//*可以专门编写一个函数求各学生的平均分,存到aver[4]数组*/#include <stdio.h>void avcour1(float score[][5]);void fali2(int num[4],float score[4][5]);void good(int num[4],float score[4][5]);main(){int i,j,num[4];//数组num代表学号float score[4][5];printf("Input NO. and scores: \n");for(i=0;i<4;i++){ printf("NO.");scanf("%d",&num[i]);printf("scores:");for(j=0;j<5;j++)scanf("%f",&score[i][j]);}printf("\n\n");avcour1(score); /*求出第一门课的平均成绩*/ printf("\n\n");fali2(num,score); /*找出2门课不及格的学生*/printf("\n\n");good(num,score); /*找出成绩好的学生*/}void avcour1(float score[][5]) /*第一门课的平均成绩的函数*/{ int i;float sum,average1;sum=0.0;for(i=0;i<4;i++)sum=sum+score[0][i]; /*累计每个学生的得分*/ average1=sum/4; /*计算平均成绩*/printf("course 1 average score: %6.2f. \n",average1);}void fali2(int num[4],float score[4][5])/*找两门以上课程不及格的学生的函数*/{ int i,j,k,label;float sum=0;printf("= = = = = = = =Student who is fail = = = = = = = = = = = =\n");printf(" NO.");for(i=0;i<5;i++)printf("%10d",i+1);printf(" average\n");for(i=0;i<4;i++){ label=0;for(j=0;j<5;j++)if((score[i][j])<60.0) label++;if(label>=2){ printf("%5d",num[i]);for(k=0;k<5;k++){ printf("%10.2f",score[i][k]);sum+=score[i][k];}printf("%10.2f\n",sum/5);}}}void good(int num[4],float score[4][5])/*找成绩优秀的学生(各门85分以上或平均90分以上)的函数*/ { int i,j,k,n;float sum=0,aver[4];printf("= = = = = = = =Student whose score is good= = = = = = = =\n");printf(" NO.");for(i=0;i<5;i++)printf("%10d",i+1);printf(" average\n");for(i=0;i<4;i++){ n=0;sum=0;for(j=0;j<5;j++){if((score[i][j])>85.0) n++;sum+=score[i][j];}aver[i]=sum/5;if((n==5)||(aver[i]>=90)){ printf("%5d",num[i]);for(k=0;k<5;k++)printf("%10.2f",score[i][k]);printf("%10.2f\n",aver[i]);}}}(6)/*习题9-4-6*/#include <math.h>double sigma(double (*fn)(double),double l,double u){ double sum=0,d;for(d=l; d<u; d+=0.1)sum+=fn(d);return sum;}void main(){ double sum;sum=sigma(sin,0.1,1.0);printf("sum of sin from 0.1 to 1.0 is: %f\n",sum);sum=sigma(cos,0.5,3.0);printf("sum of cos from 0.5 to 3.0 is: %f\n",sum);}(7)/*习题9-4-7 */main(){ int i;char *month_name(int n);printf("input Month No.:\n");scanf("%d",&i);printf("Month No.:%2d --> %s\n",i,month_name(i)); /*调用指针函数month_name()*/ }char *month_name(int n)/*定义一个指针函数month_name(),返回一个指向字符串的指针*/{ static char *name[]={"Illegal Month","January", "February", "March", "April","May", "June", "July", "August","September", "October", "November", "December"};return((n<1||n>12)?name[0]:name[n]);}(8)/*习题9-4-8 */#include <stdio.h>#include <string.h>#define N 10main(){ void sort(char *p[]);int i;char *p[N],str[N][20];for(i=0;i<N;i++)p[i]=str[i]; /*将第i个字符串的首地址赋予指针数组p的第i个元素*/ printf("Input strings:\n");for(i=0;i<N;i++)scanf("%s",p[i]);sort(p);printf("Now, the sequence is:\n");for(i=0;i<N;i++)printf("%s\n",p[i]);}void sort(char *p[]){ int i,j;char *temp;for(i=0;i<N-1;i++)for(j=0;j<N-1-i;j++)if(strcmp(*(p+j),*(p+j+1))>0){ temp=*(p+j);*(p+j)=*(p+j+1);*(p+j+1)=temp;}}(9)/*习题9-4-9 */#include <stdio.h>#define LINEMAX 20 /*定义字符串的最大长度*/main(){ void sort(char **p);int i;char **p,*pstr[5],str[5][LINEMAX];for(i=0;i<5;i++)pstr[i]=str[i]; /*将第i个字符串的首地址赋予指针数组pstr的第i 个元素*/printf("Input 5 strings:\n");for(i=0;i<5;i++)scanf("%s",pstr[i]);p=pstr;sort(p);printf("strings sorted:\n");for(i=0;i<5;i++)printf("%s\n",pstr[i]);}void sort(char **p) /*冒泡法对5个字符串排序的函数*/ { int i,j;char *temp;for(i=0;i<5;i++){ for(j=i+1;j<5;j++){ if(strcmp(*(p+i),*(p+j))>0) /*比较后交换字符串地址*/{ temp=*(p+i);*(p+i)=*(p+j);*(p+j)=temp;}}}}(10)void StrOR(char xx[][80],int maxline){ int i,righto,j,s,k;char temp[80];for(i=0; i<maxline; i++)for(j=strlen(xx[i])-1; j>=0; j--){ k=0; memset(temp,0,80);if(xx[i][j]=='o'){ righto=j;for(s=righto+1; s<strlen(xx[i]); s++)temp[k++]=xx[i][s];for(s=0;s<righto;s++)if(xx[i][s]!='o') temp[k++]=xx[i][s];strcpy(xx[i],temp);}else continue;}}C语言第十章参考答案1. 选择dccda cab2..填空(1)struct studentstrcmp(str,stu[i].name)==0break;(2)p=personp-person<3old=p->age;q->name,q->age(3)p!=NULLc++p->next(4)&per[i].body.eye&per[i].body.f.height&per[i].body.f.weight3.编程题(1)#include <stdio.h>struct data{ int year;int month;int day;};main(){ struct data a;int monthnum[12]={31,28,31,30,31,30,31,31,30,31,30,31};int i,sum=0;scanf("%d%d%d",&a.year,&a.month,&a.day);for(i=0;i<a.month-1;i++)sum+=monthnum[i];sum+=a.day;if(a.year%4==0 && a.year%100!=0 ||a.year%400==0)sum+=1;printf("%d年%d月%d日is the %d day",a.year,a.month,a.day,sum); }(2)#include <stdio.h>#include <stdlib.h>struct study{ float chinese;float maths;float english;float avg;};main(){ struct study student;scanf("%f%f%f",&student.chinese,&student.maths,&student.english);student.avg=(student.chinese+student.maths+student.english)/3;printf("average score is %f\n",student.avg);}(3)#include <stdio.h>#include <stdlib.h>struct study{ int num;float chinese;float maths;float english;float avg;};main(){ struct study s[3];struct study *p;for(p=s;p<s+3;p++){ scanf("%d%f%f%f",&(p->num),&(p->chinese),&(p->maths),&(p->english));p->avg=(p->chinese+p->maths+p->english)/3;}for(p=s;p<s+3;p++)printf("%d %3.1f %3.1f %3.1f %3.1f\n",p->num,p->chinese,p->maths,p->english,p->a vg);}(4)#include <stdio.h>#include <string.h>#define N 3typedef struct{char dm[5]; /*产品代码*/char mc[11]; /* 产品名称*/int dj; /* 单价*/int sl; /* 数量*/long je; /* 金额*/} PRO;void SortDat(PRO sell[],int n){ int i,j;PRO xy;for(i=0; i<N-1; i++)for(j=i+1; j<N; j++)if(strcmp(sell[i].mc,sell[j].mc)>0||strcmp(sell[i].mc,sell[j].mc)==0&&sell[i].je>sell[j].je) { xy=sell[i];sell[i]=sell[j];sell[j]=xy;}}void main(){ PRO sell[N];int i;for(i=0; i<N; i++){scanf("%s%s",sell[i].dm,sell[i].mc); //可这样输入,如:101 aaascanf("%d%d",&sell[i].dj,&sell[i].sl); //可这样输入,如:10 20sell[i].je=sell[i].dj*sell[i].sl;}SortDat(sell,N);printf("dm\t\tmc\t\tdj\tsl\tje\n");for(i=0; i<N; i++){printf("%s\t\t%s\t\t%d\t%d\t%ld\n",sell[i].dm,sell[i].mc,sell[i].dj,sell[i].sl,sell[i].je);}}(5)#include <stdio.h>#include <stdlib.h>main(){int *pi;int i,j,t,n;printf("输入整数个数:");scanf("%d",&n);pi=(int *)malloc(n*sizeof(int));printf("输入整数:");for(i=0; i<n; i++)scanf("%d",&pi[i]);for(i=0; i<n-1; i++)for(j=i+1; j<n; j++)if(pi[i]>pi[j]){t=pi[i]; pi[i]=pi[j]; p i[j]=t;}for(i=0; i<n; i++)printf("%d ",pi[i]);printf("\n");free(pi);}#include <stdio.h>#include <stdlib.h>struct stu{ int num;char name[20];int age;struct stu *next;};void list(struct stu *head){ struct stu *p;printf("The list records are:\n");p=head;if(head!=NULL)do{ printf("%d\t%s\t%d\n",p->num,p->name,p->age);p=p->next;}while(p!=NULL);elseprintf("The list is null");}struct stu * insert(struct stu *head,struct stu *stud){ struct stu *p0,*p1,*p2;p1=head; /*p1指向链表第一个节点*/ p0=stud; /*p0指向要插入的节点*/if(head==NULL) /*原链表是空表*/{ head=p0;p0->next=NULL; /*p0作为头指针*/ }else{ while((p1!=NULL)&&(p0->num>=p1->num)){ p2=p1;p1=p1->next;} /*p1指针后移*/if(p1!=NULL){ if(head==p1) head=p0;/*插入链表开头*/else p2->next=p0; /*插入到p2节点之后*/p0->next=p1;}else{ p2->next=p0;p0->next=NULL;}/*插入到最后*/return head;}main(){ struct stu *newstu,*head;head=NULL;int num;scanf("%d",&num);while(num!=0){ newstu=(struct stu *)malloc(sizeof(struct stu));newstu->num=num;scanf("%s",newstu->name);scanf("%d",&newstu->age);head=insert(head,newstu);scanf("%d",&num);}list(head);}(7)#include <stdio.h>void partition(unsigned long int num){ union a{ unsigned short int part[2];unsigned long int w;}n,*p;p=&n;n.w=num;printf("long int=%lx\n",num);printf("low part num=%0x,high part num=%0x\n",p->part[0],p->part[1]); }main(){ unsigned long int x;x=0x23456789; //这是为了调试方便,应改为scanf函数partition(x);}C语言第十一章参考答案一、选择1.B2.A3.B4.C5.B6.C7.D8.C9.C、D 10.A 11.A 12.C 13.B二、填空1 :fopen(fname,"w")ch2:"r"fgetc(fp) 或getc(fp)3:"bi.dat"&jfp4:==NULLflag==1s[strlen(s)-1]=='\n'三、改错题1:第一处改为:long num=0;第二处改为: !feof(fp) 或!=0改为==02: 第一处改为:rewind(fp)第二处改为: fgetc(fp)!= '\n' '\0'后面加上&& feof(fp)!=1四、编程题(1)#include<stdio.h>#include <stdlib.h>#include <string.h>main(){FILE *fp;char str[100];int i=0;if((fp=fopen("myfile","w"))==NULL){ printf("Can not open the file.\n");exit(0);}printf("Input a string:\n");gets(str);while(str[i]!='!'){ if(str[i]>='a'&& str[i]<='z')str[i]=str[i]-32;fputc(str[i],fp);i++;}fclose(fp);fp=fopen("myfile","r");fgets(str,strlen(str)+1,fp);printf("%s\n",str);fclose(fp);}(2)#include<stdio.h>struct student{ char num[10];char name[8];int score[3];float ave;}stu[5];main(){int i,j,sum;FILE *fp;for(i=0;i<5;i++){ printf("\nInput score of student %d:\n",i+1);printf("NO.:");scanf("%s",stu[i].num);printf("name:");scanf("%s",stu[i].name);sum=0;for(j=0;j<3;j++){ printf("score %d:",j+1);scanf("%d",&stu[i].score[j]);sum+=stu[i].score[j];}stu[i].ave=sum/3.0;}fp=fopen("stud","w");for(i=0;i<5;i++)if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1)printf("File write error\n");fclose(fp);fp=fopen("stud","r");for(i=0;i<5;i++){ fread(&stu[i],sizeof(struct student),1,fp);printf("%s,%s,%d,%d,%d,%6.2f\n",stu[i].num,stu[i].name,stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].ave);}}(3)#include<stdio.h>#include <stdlib.h>main(){char s[80];int a;FILE *fp;if((fp=fopen("test","w"))==NULL){ printf("Cannot open file.\n");exit(1);}fscanf(stdin,"%s%d",s,&a); //相当于scanffprintf(fp,"%s %d",s,a);fclose(fp);if((fp=fopen("test","r"))==NULL){ printf("Cannot open file.\n");exit(1);}fscanf(fp,"%s %d",s,&a);fprintf(stdout,"%s %d\n",s,a); //相当于printf fclose(fp);}(4)#include<stdio.h>#include <stdlib.h>main(){FILE *fp;int i,j,n,i1;char c[100],t,ch;if((fp=fopen("A","r"))==NULL){printf("Can not open the file.\n");exit(0);}printf("\nfile A:\n");for(i=0;(ch=fgetc(fp))!=EOF;i++){c[i]=ch;putchar(c[i]);}fclose(fp);i1=i;if((fp=fopen("B","r"))==NULL){ printf("\n Can not open the file.");exit(0);}printf("\nfile B:\n");for(i=i1;(ch=fgetc(fp))!=EOF;i++){c[i]=ch;putchar(c[i]);}fclose(fp);n=i;for(i=0;i<n;i++)for(j=i+1;j<n;j++)if(c[i]>c[j]){ t=c[i];c[i]=c[j];c[j]=t;}printf("\n file C:\n");fp=fopen("c","w");for(i=0;i<n;i++){ putc(c[i],fp);putchar(c[i]);}fclose(fp);}(5)#include<stdio.h>main(){FILE *fp1,*fp2;char ch;fp1=fopen("file1.c","r");fp2=fopen("file2.c","w");ch=fgetc(fp1);while(!feof(fp1)){putchar(ch);ch=fgetc(fp1);}rewind(fp1);while(!feof(fp1))fputc(fgetc(fp1),fp2);fclose(fp1);fclose(fp2);}(6)#include<stdio.h>main(){FILE *fp; long position;fp=fopen("data.txt","w");position=ftell(fp);printf("position=%ld\n",position);fprintf(fp,"Sample data\n");position=ftell(fp);printf("position=%ld\n",position);fclose(fp);}第12章1.选择题(1)D (2)C (3)D (4)D (5)C(6)D (7)D (8)B (9)A (10).C2.填空题(1) //(2) public、private 、protected(3) 函数类型类名::函数名(形参表列) 或类型类名::函数名(参数表)(4) 内联函数(5) 构造函数(6) 类名, 创建对象时(7) 私有(8) 私有(9) 基类的构造函数成员对象的构造函数派生类本身的构造函数3.概念题(1)答:本质差别是C++是面向对象的,而C语言是面向过程的。
C语言程序设计(第三版)谭浩强著 各章习题答疑
以八、 /* 以八、十六进制输出 */
} ???? 是对应的带符号短整数。 输出结果是八进制整数 十六进制整数
2
3.9 计算某个表达式的值。 通用程序清单如下: stdio.h” #include ”stdio.h stdio.h void main() { ?????? x; 计算表达式值存入x x=( 表达式 );/* 计算表达式值存入x */ printf(”% printf( %?\n”,x); ,x); } ?????? 表达式对应的数据类型符(需事先判断) ? 表达式为整型,则为d 表达式为实型,则为f 3
第七章习题答疑(二)
折半查找法在排序数组中查找某个数。 上课时已有提示。 7.13 字符串连接(b[]中字符串连接到a[]中字符串后) 设:a[10]=”12 ,b[]=”abc 12”, abc” 12 abc (1)找到a串的’\0’的下标(i=2) ’ (2)j=0; 当型循环(b[j]!=’\0’) ’\ ’ a[i]=b[j],i++,j++ (3)a[i]=’\0’ \ 7.15 字符串复制(b[]中字符串复制到a[]中) 设:a[10]=”12”,b[]=”abc” (1)i=0; 当型循环(b[i]!=’\0’) a[i]=b[i],i++ (2)a[i]=’\0’ 7.9
18
第十章习题答疑(一)
输入3个整数,按照由小到大顺序输出。 int x,y,z,*px=&x,*py=&y,*pz=&x; 用以前的程序,其中的x、y、z换成*px、*py、*pz 10.3 输入10个整数存入一维数组a[10],将其中最小数与第1 个数交换,最大数与最后一个数交换。 要求编3个函数: 10 10 输入10个整数、交换、输出交换后的10个整数。 输入函数: void in(int *p,int n) 输出函数: void out(int *p,int n) 交换函数: void change(int *p,int n) 其中寻找最大最小数的方法: int *q,*max,*min; for (max=min=p,q=p+1;q<p+n;q++) { if(*max<*q) max=q; if(*min>*q) min=q; } 19 交换的方法:*p和*min,*(p+n-1)和*max 10.1
《C语言程序设计教程》(第三版)李凤霞 主编——第九章习题答案
习题九一、单选题1、已知:int *p,a;则语句"p=&a;"中的运算符"&"的含义是()。
A)位与运算 B)逻辑与运算 C)取指针内容D)取变量地址2、已知:int a,x;则正确的赋值语句是()。
A)a=(a[1]+a[2])/2 B)a*=*a+1; C)a=(x=1,x++,x+2); D)a="goog";3、已知:int a,*p=&a; 则下列函数调用中错误的是()。
A)scanf("%d",&a); B)scanf("%d",p); C)printf("%d",a); D)printf("%d",p);4、main(argc,argv)中形式参数argv的正确说明形式应当为()。
A)char *argv[ ] B)char argv[ ][ ] C)char argv[ ] D)char *argv5、说明语句"int (*p)(); "的含义是()。
A)p是一个指向一维数组的指针变量B)p是一个指针变量,指向一个整型数据C)p是一个指向函数的指针,该函数的返回值是一个整型D)以上都不对6、设有说明int(*ptr)[M];其中的标识符ptr是()。
A)M个指向整型变量的指针B)指向M个整型变量的函数指针C)一个指向有M个整型元素的一维数组的指针D)具有M个指针元素的一维指针数组,每个元素都只能指向整型变量7、已知:double *p[6]; 它的含义是()。
A)p是指向double型变量的指针 B)p是double型数组C)p是指针数组 D)p是数组指针8、已知函数说明语句:void *f(); 则它的含义是()。
A)函数f的返回值是一个通用型的指针 B)函数f的返回值可以是任意的数据类型C)函数f无返回值D)指针f指向一个函数,该函数无返回值9、已知:char s[10],*p=s,则在下列语句中,错误的语句是()。
C语言习题及答案(第九章)
9-3编写程序,使用结构体类型,输出一年十二个月的英文名称及相应天数。
解:#include "stdio.h"struct date{char month[10] ;int daynumber ;}main(){int i ;struct datea[12]={{"January",31},{"February",29},{"March",31},{"Aprial",30},{ "May",31},{"June",30},{"july",31},{"August",31},{"September",30}, {"October",31},{"November",30},{"December",31}} ;for(i=0;i<12;i++);printf("%d 月:%s %d\n",i+1,a[i].month,a[i].daynumber) ;}思考:如何对结构体变量进行初始化?对结构体变量的引用为何要体现为分量(或成员)的引用?9-4 编写程序求空间任一点到原点的距离,点用结构体描述。
并请考虑求空间中任意两点的距离的程序。
解:#include "stdio.h"#include "math.h"struct point{float x ;float y ;float z ;} main(){double d1,d2,d ;struct point p1,p2 ;printf("请输入第一个点的坐标:");scanf("%f,%f,%f",&p1.x,&p1.y,&p1.z);printf("请输入第二个点的坐标:");scanf("%f,%f,%f",&p2.x,&p2.y,&p2.z);d1=sqrt(p1.x*p1.x+p1.y*p1.y+p1.z*p1.z);d2=sqrt(p2.x*p2.x+p2.y*p2.y+p2.z*p2.z);d=sqrt((p2.x-p1.x)*(p2.x-p1.x)+(p2.y-p1.y)*(p2.y-p1.y)+(p2.z-p1.z)*( p2.z-p1.z));printf("第一个点到原点的距离:%f\n",d1);printf("第二个点到原点的距离:%f\n",d2);printf("两点间的距离:%f\n",d);}9-5 编写输入、输出10个朋友数据的通讯录程序,每个朋友数据包括姓名、地址、邮编、电话、传呼、手机等数据。
《C语言程序设计教程》第三版课后习题参考答案
《C语言程序设计教程》第三版课后习题参考答案C语言程序设计教程第三版课后习题参考答案第一章:C语言概述1.1 C语言的特点答案:C语言是一种通用的、面向过程的程序设计语言,具有高效、简洁、灵活等特点。
它提供了丰富的程序设计元素和功能,适用于各种不同的应用领域。
1.2 C语言程序的基本结构答案:C语言程序由预处理指令、函数声明、函数定义、变量声明和语句组成。
其中,预处理指令用来引入头文件或定义宏,函数声明用来声明函数的名称和参数,函数定义用来实现函数的功能,变量声明用来声明变量的类型和名称,语句用来表达具体的计算过程。
1.3 C语言的数据类型答案:C语言提供了多种数据类型,包括基本类型(整型、浮点型、字符型等)和派生类型(数组、指针、结构体等)。
每种数据类型在内存中占据一定的存储空间,并具有特定的取值范围和操作规则。
1.4 C语言的运算符和表达式答案:C语言支持各种运算符和表达式,例如算术运算符(+、-、*、/等)、关系运算符(>、<、==等)、逻辑运算符(&&、||、!等)等。
通过运算符和表达式可以进行各种数值计算和逻辑判断。
第二章:基本数据类型与运算2.1 整型数据类型答案:C语言提供了不同长度的整型数据类型,包括有符号整型(int、long等)和无符号整型(unsigned int、unsigned long等)。
整型数据类型可以表示整数值,并具有不同的取值范围。
2.2 浮点型数据类型答案:C语言提供了浮点型数据类型(float、double等),用来表示带小数部分的实数值。
浮点型数据可以表示较大或较小的数值,并具有一定的精度。
2.3 字符型数据类型答案:C语言提供了字符型数据类型(char),用来表示单个字符。
字符型数据可以用于表示各种字符(包括字母、数字、符号等)。
2.4 布尔型数据类型答案:C语言不直接支持布尔型数据类型,但可以使用整型数据类型来表示布尔值(0表示假、非零表示真)。
C语言 习题十一 参考答案
3.已有一个存放数千种仓库物质信息的文件 CK,每个信息元素含两个内容:物质编号 kno 和库存量 KNOM。请编程通过检查全库物质的库存量,建立一个新的文件 XK,它包含所有库存量大于 100 的物质 的编号和库存量。 参考程序: /*p360_3.c*/ #include "stdio.h" main() {int n,m;
{scanf("%d%s",&n,xm); for(j=0;j<5;j++) scanf("%d",&sc[i][j]); }
fp=fopen("abc.txt","w"); for(i=0;i<N;i++)
fprintf(fp,"%5d%s%4d%4d%4d%4d%4d\n",n,xm,sc[i][0],sc[i][1],sc[i][2],sc[i][3],sc[i][4]); fclose(fp); } /*p360_1a.c*/ #include "stdio.h" main() {FILE *fp; int num,mark[5],i,sum,n=0; float av,t[5]={0}; char name[20]; if((fp=fopen("abd.txt","w"))==NULL)
FILE *fp1,*fp2; fp1=fopen("ck.txt","r"); fp2=fopen("xk.txt","w"); while(feof(fp1)==0) {fscanf(fp1,"%d,%d",&n,&m);
C语言第九章习题带答案
练习9-1答案一、选择题1.typedef unsigned long LONG的作用是( D )。
A.建立了一种新的数据类型B.定义了一个整形变量C.定义了一个长整型变量D.定义了一个新的数据类型标识符2.下面的4个运算符中,优先级最低的是( D )。
A.( ) B.. C.-> D.++3.已知:struct{int i;char c;float a;} test;则sizeof(test)的值是( D )。
A.4 B.5 C.6 D.74.当声明一个结构变量时系统分配给它的内存是( A )。
A.各成员所需内存量的总和B.结构中第一个成员所需内存量C.成员中占内存量最大者所需的容量D.结构中最后一个成员所需内存量5.以下对结构类型变量的定义中错误的是( D )。
A.typedef struct student B.struct student{ i nt num; {int num;float age; float age;} STUDENT std1; } std1;C.struct D.struct{ i nt num; {int num;float age; float age;} std1; } student;struct student std1;6.根据下面的定义,能打印出字母M的语句是( D )。
struct person{char name[9];int age;};struct person class[10]={"John", 17, "Paul", 19, "Mary", 18, "adam", 16};A.printf("%c\n", class[3].name); B.printf("%c\n", class[3].name[1]);C.printf("%c\n", class[2].name[1]); D.printf("%c\n", class[2].name[0]); 7.以下scanf函数调用语句中对结构变量成员的错误引用是( D )。
《C语言程序设计教程》(第三版)课后习题参考答案(精选5篇)[修改版]
第一篇:《C语言程序设计教程》(第三版)课后习题参考答案C语言程序设计课后习题参考答案习题一一、单项选择题1、C2、B3、B4、C5、D6、A7、C8、A二、填空题1、判断条件2、面向过程编程3、结构化4、程序5、面向对象方法6、基本功能操作、控制结构7、有穷性8、直到型循环结构9、算法10、可读性11、模块化12、对问题的分解和模块的划分习题二一、单项选择题1、B2、D3、C4、B5、A二、填空题1、主2、C编译系统3、结构化4、程序5、面向对象方法6、.OBJ7、库函数8、直到型循环结构习题三一、单项选择题1、D2、B3、A4、C9、B10、C11、A12、D13、C17、B18、C19、C20、D21、A25、D26、A二、填空题1、补码2、10^-138~10^1 38、15~166、A7、B6、D7、B14、B15、C22、D8、C8、D16、A24、D、A3、实4、单目运算符、自右向左5、函数调用6、65,89习题四一、单项选择题1、D2、C3、D4、A5、D6、B7、A8、C9、B10、B二、填空题1、两, ;2、5.1690003、-200 2500、i=-200,j=2500回车、i=-200回车j=2500回车4、a=98,b=765.000000,c=4321.0000005、100 25.81 1.89234、100,25.81,1.89234、100回车25.81回车1.89234回车6、0,0,37、38、scanf(“%lf %lf %lf”,&a,&b,&c);9、13 13.000000 13.00000010、c=b-a;a=b+c;习题五一、单项选择题1、B2、D3、C4、B5、B6、D7、A8、B二、填空题1、1 、02、k!=03、if(x>4||xelse printf(“error!”); 4、if(((x>=1&&x=200&&x Printf(“%d”,x);5、16、17、10! Right!8、a=09、2,110、0习题六一、单项选择题9、D1、B2、C3、C4、B5、C6、B7、C8、A二、填空题1、无穷次2、83、205、3.66、*#*#*#$7、828、d=1.0 、k++、k9、!(x习题七一、单项选择题1、B2、D3、C4、C5、A二、填空题1、1 2 4 8 16 32 64 128 256 5122、a[age]++、i=18;i3、break、i==84、a[i]>b[i]、i3、j5、b[j]=0、b[j]=a[j][k]习题八一、单项选择题1、B3、C4、A5、A9、D10、B11、A12、C13、A二、填空题1、return1、return n+sum(n-1)2、return1、n*facto(n-1)习题九一、单项选择题1、D2、C3、D4、A5、C9、B10、C11、A13、B17、C18、A19、B20、C二、填空题1、int 、return z2、*p++3、’\0’、++4、p、max*q6、A7、D6、A7、C14、C15、B6、C7、C14、A15、D8、A8、D8、C习题十一、单项选择题1、D2、D3、A4、5、B6、A7、C8、B9、D10、11、C12、D13、D14、C二、填空题1、34 122、ARRAY a[10],b[10],c[10];3、2 34、ab、cd5、(*b).day、b->day6、adghi mnohi no7、(struct node *)、!=’\n’、p=top;8、p1=p1->next9、(struct list *)、(struct list *)、return (n)习题十一一、单项选择题1、A2、A3、B4、A5、B9、A10、B11、B12、B13、C17、D二、填空题1、ASCII(文本)、二进制2、pf=fopen(“A:\zk04\data xfile.dat”,”w”);3、fputc()、fputs()、fscanf()、fread()4、(后两个空)文件结束符、非0值7、B14、C15、D8、A16、A第二篇:C语言程序设计教程课后习题参考答案《C语言程序设计教程》课后习题参考答案习题1 1. (1)编译、链接.exe (2)函数主函数(或main函数)(3)编辑编译链接2.(1)-(5):DDBBC (6)-(10):ABBBC 3.(1)答:C语言简洁、紧凑,使用方便、灵活;C语言是高级语言,同时具备了低级语言的特征;C 语言是结构化程序设计语言,具有结构化的程序控制语句;C语言有各种各样的数据类型;C语言可移植性好;生成目标代码质量高,程序执行效率高。
C语言理论教材各章后习题参考答案第九章习题
第九章习题参考答案一、选择题9.1 答案:B9.2 答案:C9.3 答案:D9.4 答案:B9.5 答案:D9.6 答案:C9.7 答案:C9.8 答案:D9.9 答案:B9.10 答案:D二、读程序回答问题9.11 答案:C9.12 答案:A9.13 答案:A9.14 答案:D9.15 答案:C三、程序填空9.16答案:①FILE *fp;② "Ef9-16.txt","w"或"Ef9-16.txt","w+";③ch,fp。
9.17答案:①Ef9-17.dat;② 8*sizeof(char)。
9.18 答案:①fopen; ② SEEK_END或2。
9.19 答案:①fname; ②fp。
9.20 答案:①argc!=2; ②r; ③NULL; ④row++ ; ⑤fclose(fp)。
四、编写程序9.21 从键盘输入一行字符串,将其中的小字母全部转换成大写字母,然后输出到一个磁盘文件" Ef9-21.txt"中保存。
参考源程序如下:#include <stdio.h>void main( ){FILE *fp;char str[100];int i;if ((fp=fopen("Ef9-21.txt ", "w")) == NULL) {printf ("Cannot open the file.\n");exit(0);}printf ("Input a string:");gets (str); /* 读入一行字符串 */for (i=0; str[i]&&i<100; i++) { /* 处理该行中的每一个字符 */if (str[i] >= 'a' && str[i] <= 'z') /* 若是小写字母 */str[i] -= 'a' - 'A'; /* 将小写字母转换为大写字母 */fputc (str[i], fp); /* 将转换后的字符写入文件 */}fclose (fp); /* 结束文件输入操作关闭文件 */}9.22文件Ef9-22.txt中存放了一个学生各门课程的考试分数,数据之间以逗号分割。
c程序设计第四版(谭浩强)第九章答案
#include<stdio.h>#include<stdlib.h>/*int days(inty,intm,int d) //计算天数{int days=0,i;int a[12]={31,28,31,30,31,30,31,31,30,31,30,31};if(y%4==0&&y%100!=0||y%400==0) //判断是否为闰年a[1]+=1;if(m==1)return days;else{for(i=0;i<m-1;i++)days+=a[i];days+=d;return days;}}struct date{int year;int month;int day;int days;}a;int main(){printf("enter date:");scanf("%d %d %d",&a.year,&a.month,&a.day);a.days=days(a.year,a.month,a.day);printf("%d年%d月%d日是该年的第%d天\n",a.year,a.month,a.day,a.days); }*//*#define N 10 //第3、4题时N为5,第5题时N为10 struct student{intnum;char name[20];float score[3];float ave; //第3、4、5题共用一个结构体类型}stu[N];*/void print(struct student a[]){inti;printf("学号姓名\t三门课成绩\n");for(i=0;i<N;i++)printf("%ld %s\t%-5.1f %-5.1f %-5.1f\n",a[i].num,a[i].name,a[i].score[0],a[i].score[1],a[i].sc ore[2]);}int main(){inti;printf("请输入%d个学生的信息:学号、姓名、三门课成绩:\n",N);for(i=0;i<N;i++)scanf("%d %s %f %f %f",&stu[i].num,&stu[i].name,&stu[i].score[0],&stu[i].score[1],&stu[i].sc ore[2]);print(stu);}*//*void print(struct student a[]){inti;printf("学号姓名\t三门课成绩\n");for(i=0;i<N;i++)printf("%ld %s\t%-5.1f %-5.1f %-5.1f\n",a[i].num,a[i].name,a[i].score[0],a[i].score[1],a[i].sc ore[2]);}void input(struct student a[]) //在上一题的基础上编写input函数{inti;printf("请输入%d个学生的信息:学号、姓名、三门课成绩:\n",N);for(i=0;i<N;i++)scanf("%d %s %f %f %f",&stu[i].num,&stu[i].name,&stu[i].score[0],&stu[i].score[1],&stu[i].sc ore[2]);}int main(){input(stu);print(stu);*//*测试数据10101 wu 70 71 9010102 chen 60 64 9010103 guo 80 78 9010104 lu 80 64 9010105 xu 60 65 9010106 huang 90 78 9010107 chen 70 66 9010108 rong 90 72 9010109 yang 50 63 9010110 zhang 50 71 90*//*int main(){inti,m=0;float average=0;printf("请输入%d个学生的信息:学号、姓名、三门课成绩:\n",N);for(i=0;i<N;i++){scanf("%d %s %f %f %f",&stu[i].num,&stu[i].name,&stu[i].score[0],&stu[i].score[1],&stu[i].sc ore[2]);stu[i].ave=(stu[i].score[0]+stu[i].score[1]+stu[i].score[2])/3;average+=stu[i].ave/N;}for(i=1;i<N;i++)if(stu[i].ave>stu[m].ave)m=i;printf("三门课程总平均成绩为:%5.1f\n成绩最高的学生是:\n学号:%d\n姓名:%s\n三门课成绩:%5.1f,%5.1f,%5.1f\n平均成绩:%6.2f\n",average,stu[m].num,stu[m].name,stu[m].score[0],stu[m].score[1],stu[m].score[2],st u[m].ave);}*//*#define N 13 //定义人数struct a{intnum; //原来的序号int count; //报数数目struct a *next;};int main(){inti,j=1;struct a *p1,*p2,b[N];p1=b;for(i=0;i<N;i++){b[i].num=i+1; //定义序号为1到13if(i==N-1)b[i].next=&b[0]; //将最后一个节点的指针变量指向第一个节点elseb[i].next=&b[i+1]; //将每个节点的指针变量指向下一个节点}while(p1->next!=p1) //p1的next成员指向自己时表明只剩最后一个人{p1->count=j; //报数if(j==2)p2=p1; //p2的作用是标记报数为2的人if(j==3){j=1;p2->next=p1->next;//将报数为3的next成员赋值给上一个报数为2的next成员,使之指向下一个报数为1的//成员;}elsej+=1;p1=p1->next; //p1指向下一个count不为3的成员}printf("最后留在圈子的人原来的序号为:%d\n",p1->num);}*//*# define L sizeof(struct student)struct student{longnum;float score;struct student *next;};int n;struct student *creat(void) //生成单向动态链表的函数{struct student *head;struct student *p1,*p2;n=0;p1=p2=malloc(L);scanf("%ld,%f",&p1->num,&p1->score);head=NULL;while(p1->num!=0){n+=1;if(n==1)head=p1;else p2->next=p1;p2=p1;p1=malloc(L);scanf("%ld,%f",&p1->num,&p1->score);}p2->next=NULL;return head;}void print(struct student *head) //输出链表的函数{struct student *p=head;printf("\nnow,these records are:\n");while(p!=NULL){printf("%ld %5.1f\n",p->num,p->score);p=p->next;}}struct student *del1(struct student *head,longnum) //删除指定节点的函数,方法一,指定删除节点的数据{struct student *p1,*p2;p1=head;if(p1->num==num)return head=p1->next;else{while(p1->num!=num){p2=p1;p1=p1->next;}p2->next=p1->next;p1->next=NULL;return head;}}struct student *del2(struct student *head,int n) //方法二,指定删除节点序号{struct student *p1,*p2;inti=1;p1=head;if(i==n)return head=p1->next;else{while(i++<n){p2=p1;p1=p1->next;}p2->next=p1->next;p1->next=NULL;return head;}}int main(){struct student *head;longnum; //int n;head=creat();print(head);printf("\n输入要删除学生的学号:"); //printf("\n输入要删除节点序号:");scanf("%ld",&num); //scanf("%d",&n);head=del1(head,num); //head=del2(head,n);print(head);}*//*# define L sizeof(struct student)struct student{longnum;float score;struct student *next;};int n;struct student *creat(void) //生成单向动态链表的函数{struct student *head;struct student *p1,*p2;n=0;p1=p2=malloc(L);scanf("%ld,%f",&p1->num,&p1->score);head=NULL;while(p1->num!=0){n+=1;if(n==1)head=p1;else p2->next=p1;p2=p1;p1=malloc(L);scanf("%ld,%f",&p1->num,&p1->score);}p2->next=NULL;return head;}void print(struct student *head) //输出链表的函数{struct student *p=head;printf("\nnow,these records are:\n");while(p!=NULL){printf("%ld %5.1f\n",p->num,p->score);p=p->next;}}struct student *del1(struct student *head,longnum)//删除指定节点的函数,num为指定删除节点的数据{struct student *p1,*p2;p1=head;if(p1->num==num)return head=p1->next;else{while(p1->num!=num){p2=p1;p1=p1->next;}p2->next=p1->next;p1->next=NULL;return head;}}struct student *insert(struct student *head,struct student *p,int n) //插入节点的函数,n为新节点序号{struct student *p1,*p2;inti=1;p1=head;if(i==n){p->next=p1;head=p;}else{while(i++<n){p2=p1;p1=p1->next;}p2->next=p;p->next=p1;}return head;}int main(){struct student *head,*p;int n;longnum;head=creat();print(head);printf("\n输入要删除学生的学号:");scanf("%d",&num);head=del(head,num);print(head);p=malloc(L);//为插入的新节点开辟单元,否则p的值不确定printf("\n输入要添加学生的学号,成绩,序号:");scanf("%ld,%f,%d",&p->num,&p->score,&n);head=insert(head,p,n);print(head);}*//*# define L sizeof(struct student)struct student{intnum;float score;struct student *next;};int n;struct student *creat(void) //生成单向动态链表的函数{struct student *head;struct student *p1,*p2;n=0;p1=p2=malloc(L);scanf("%d %f",&p1->num,&p1->score);head=NULL;while(p1->num!=0){n+=1;if(n==1)head=p1;else p2->next=p1;p2=p1;p1=malloc(L);scanf("%d %f",&p1->num,&p1->score);}p2->next=NULL;return head;}void print(struct student *head) //输出链表的函数{struct student *p=head;printf("\nnow,these records are:\n");while(p!=NULL){printf("%d %5.1f\n",p->num,p->score);p=p->next;}}struct student *sort(struct student *head) //建立链表排序函数{struct student *p1,*p2;int t;float s;p1=head;p2=p1->next;while(p1&&p2)//不能写为p1,否则当p1指向最后一个结点时,最后一句循环语句出问题{while(p2){if(p1->num>p2->num){t=p1->num;s=p1->score;p1->num=p2->num;p1->score=p2->score;p2->num=t;p2->score=s;p2=p2->next;}else //不能省略else语句,否则遇到p1->num<p2->num时无限循环p2=p2->next;}p1=p1->next;p2=p1->next;}return head;}struct student *cat(struct student *head1,struct student *head2) //建立链表合并函数{struct student *p,*t;p=head1;while(p){t=p; //循环结束时t将指向a链表的最后一个指针p=p->next;}t->next=head2;return head1;}int main(){struct student *a,*b;printf("输入链表a:\n");a=creat();printf("输入链表b:\n");b=creat();print(sort(cat(a,b)));}*//*测试数据10018 8910016 6410014 8110012 940 010017 6710015 6810013 7610011 850 0*//*# define L sizeof(struct student)struct student{longnum;char name[20];struct student *next;};int n;struct student *creat(void) //生成单向动态链表的函数{struct student *head;struct student *p1,*p2;n=0;p1=p2=malloc(L);scanf("%ld %s",&p1->num,p1->name);head=NULL;while(p1->num!=0){n+=1;if(n==1)head=p1;else p2->next=p1;p2=p1;p1=malloc(L);scanf("%ld %s",&p1->num,p1->name);}p2->next=NULL;return head;}void print(struct student *head) //输出链表的函数{struct student *p=head;printf("\n现在链表a为:\n");while(p!=NULL){printf("%ld %s\n",p->num,p->name);p=p->next;}}struct student *delsame(struct student *a,struct student *b) //从a中删去与b相同学号的节点{struct student *p1,*p2,*p3;longnum;ints,k=0;p3=p1=a;p2=b;while(p1){s=0;num=p1->num;while(p2){if(p2->num!=num)p2=p2->next;else{s=1;break;}}if(s==1)p3->next=p1->next; //若a最后一个相同,p3的指针数据为null else{p3=p1; //每找到一个与b不相等的指针时,p3指向它k+=1; //每找到一个与b不相等的指针时,k累加1if(k==1) //找到第一个与b不相等的指针时,将头指针赋值给aa=p1;}p1=p1->next; //p1指向下一个指针p2=b; //p2重新指向链表b开头}if(k==0) //k=0表明a,b链表相同,返回null return a=NULL;elsereturn a;}int main(){struct student *a,*b;printf("输入链表a:\n");a=creat();printf("输入链表b:\n");b=creat();a=delsame(a,b);print(a);}*//*#define L sizeof(structinf)structinf{longnum;int age;char name[20];char sex;structinf *next;};int n;structinf *creat(void) //生成单向动态链表的函数{structinf *head;structinf *p1,*p2;n=0;p1=p2=malloc(L);scanf("%ld %s %c %d",&p1->num,p1->name,&p1->sex,&p1->age);head=NULL;while(p1->num!=0){n+=1;if(n==1)head=p1;else p2->next=p1;p2=p1;p1=malloc(L);scanf("%ld %s %c %d",&p1->num,p1->name,&p1->sex,&p1->age);}p2->next=NULL;return head;}void print(structinf *head) //输出链表的函数{structinf *p=head;printf("\nnow,theseinf are:\n");while(p!=NULL){printf("%ld %s %c %d\n",p->num,p->name,p->sex,p->age);p=p->next;}}structinf *delage(structinf *head,int a) //删除指定年龄节点的函数{structinf *p1,*p2;p1=head;while(p1->age==a)p1=p1->next;head=p1;p2=p1;while(p1->next!=NULL){if(p1->age==a){p2->next=p1->next;p1=p1->next;}else{p2=p1;p1=p1->next;}}if(p1->age==a)p2->next=NULL;return head;}int main(){structinf *head;int a;head=creat();print(head);printf("\n输入要删除的年龄:");scanf("%d",&a);head=delage(head,a);print(head);}*//*测试数据10009 chen f 2410010 wang m 2810011 li f 2810012 zhao m 2810013 chen f 2410014 wei m 2510015 yang f 2610016 tian m 2810016 tian m 2810017 mei f 2710018 liu m 2810019 chen f 24*/。
C程序设计(第三版)习题答案(9、11章) 谭浩强著
}
printf("value=%format\t",x1);printf("value=%format\t",x2);putchar('\n');
输出结果:
value=5.000000ormat value=5.000000ormat
value=3.000000ormat value=8.000000ormat
break;
case 3:scanf("%s",s);
STRING(s);
break;
default:printf("error");
}
}
9.8main()
{int a,b,c;
scanf("%d,%d,%d",&a,&b,&c);
main()
{int a,b;
scanf("%d,%d",&a,&b);
printf("%d",SURPLUS(a,b));
}
9.3#include"math.h"
#define S(a,b,c) ((a+b+c)/2)
#define AREA(a,b,c) (sqrt(S(a,b,c)*(S(a,b,c)-a)*(S(a,b,c)-b)*(S(a,b,c)-c)))
scanf("%d",&stu.score[j]);
