发布时间 : 星期四 文章C语言题库更新完毕开始阅读
return com; } { struct complex com; com.real=creal->real*cim->real-creal->im*cim->im; com.im=creal->real*cim->im+creal->im*cim->real; return com; }
void main() { struct complex c1={3,4},c2={5,6},com1,com2; com1=cadd(&c1,&c2); com2=cmult(&c1,&c2); cout< 3、输入4本书的名称,单价,作者,出版社,按书名进行排版和输出。 解: #include void main() {struct book bookarray[4]={{\Fundamental\Press\Programming\Education Press\C Programming\.Kassab\Hall\Programming Language \struct book temp; int i,j,n; n=4; for(i=0;i if(strcmp(bookarray[j-1].bookname,bookarray[j].bookname)>0) {temp=bookarray[j-1]; bookarray[j-1]=bookarray[j]; bookarray[j]=temp; } 41 for(i=0;i cout< 4、编写一个程序,输入若干人员的姓名及电话号码,以字符?#?表示结束输入。然后输入姓名,查找该人的电话号码。 解:用一个结构体数组存放所有输入人员的姓名和电话号码。在输入查找人姓名后,从头到尾在该数组中顺序查找。一旦找到了,输出其电话号码,若找到末尾仍没有该姓名的元素,则显示相应信息。程序如下: #include void search(struct telephone b[],char *x,int n); struct telephone { char name[10]; char telno[20]; }; void main() { struct telephone s[MAX]; int i=0; char na[10],tel[20]; while (1) { cout<<\输入姓名\ gets(na); if(strcmp(na,\ break; cout<<\输入电话号码\ gets(tel); strcpy(s[i].name,na); strcpy(s[i].telno,tel); i++; } cout<<\查找的姓名\ gets(na); search(s,na,i); } void search(struct telephone b[],char *x,int n) { int i=0; while(strcmp(b[i].name,x)!=0 &&i 42 } i++; if(i 43