扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
#include stdio.hstruct stud
网站设计制作过程拒绝使用模板建站;使用PHP+MYSQL原生开发可交付网站源代码;符合网站优化排名的后台管理系统;网站制作、成都网站制作收费合理;免费进行网站备案等企业网站建设一条龙服务.我们是一家持续稳定运营了十载的成都创新互联公司网站建设公司。
{
int num;
char name[20];
float score1, score2, score3, aver;
}; int main(void)
{
int high;
int i, j;
struct stud myClass[10], *pStu = myClass;
struct stud temp; printf("Please input students info:Num Name score1 score2 score3\n");
for (i = 0; i 10; i++)
{
printf("%d:", i + 1);
scanf("%d %s %f %f %f", myClass[i].num, myClass[i].name, myClass[i].score1,
myClass[i].score2, myClass[i].score3);
myClass[i].aver = (myClass[i].score1 + myClass[i].score2 + myClass[i].score3) / 3;
} high = 0;
for (i = 0; i 10; i++)
{
if (myClass[i].aver myClass[high].aver)
{
high = i;
}
} printf("\nThe Highest is %s(%d)\nscore1=%.2f score2=%.2f score3=%.2f aver=%.2f\n",
myClass[high].name, myClass[high].num,
myClass[high].score1, myClass[high].score2, myClass[high].score3, myClass[high].aver); for (i = 0; i 9; i++)
{
for (j = i + 1; j 10; j++)
{
if ((pStu + j)-aver (pStu + i)-aver)
{
temp = *(pStu + j);
*(pStu + j) = *(pStu + i);
*(pStu + i) = temp;
}
}
} printf("\nResult of sort:\n");
printf("Num Name score1 score2 score3 average\n");
for (i=0; i10; i++)
{
printf("%-5d %-20s %-8.2f %-8.2f %-8.2f %-.2f\n", (pStu+i)-num, (pStu+i)-name,
(pStu+i)-score1, (pStu+i)-score2, (pStu+i)-score3, (pStu+i)-aver);
}
return 0;
}
#includestdio.h struct Class {char *cname; //名字char *cphon; //电话号码char *cuphon; //单位电话char *cmphon; //手机号码char *cqq; //qq号码char *cbday; //生日日期struct Class *node; //其余的自己可以加***** }; typedef struct Class Students; //通讯录结构 typedef Students *Ps; Ps TcraseClsSt(Ps lina); // 催的操作Ps CraseClsSt(Ps lina,char *cname,char *cphon,char *cuphon,char *cmphon,char *cqq,char *cbday); //存过程void OutSmary(Ps lina); //输出结果 void main() {Ps lina=NULL;lina=TcraseClsSt(lina);if(lina!=NULL) //如果lina为NULL是错误内存非配失败{OutSmary(lina);}elseprintf("Error");getch(); } Ps TcraseClsSt(Ps lina) {int Cmd=0;char cname[100];char cphon[100];char cuphon[100];char cmphon[100];char cqq[100];char cbday[100];do{ printf("Please enter a name:");scanf("%s",cname); //提示并输入数据printf("Enter the phone number:");scanf("%s",cphon);printf("Enter the unit telephone:");scanf("%s",cuphon);printf("Enter phone number:");scanf("%s",cmphon);printf("Enter the number qq:");scanf("%s",cqq);printf("Enter your date of birth:");scanf("%s",cbday);lina=CraseClsSt(lina,cname,cphon,cuphon,cmphon,cqq,cbday);//把数据存入链表 printf("Enter -1 to exit any exit:");scanf("%d",Cmd); } while(Cmd!=-1lina!=NULL);return lina; } Ps CraseClsSt(Ps lina,char *cname,char *cphon,char *cuphon,char *cmphon,char *cqq,char *cbday) //链表存入函数 {Ps merory;Ps linb;merory=(Ps)malloc(sizeof(Students));if(!merory){return NULL; //merory为NULL是返回零 NULL}merory-node=NULL;strcpy(merory-cname,cname); //用字符创拷贝函数 段错午 在turbo c 编译器可以通过 gcc可以用别的方法处理strcpy(merory-cphon,cphon);strcpy(merory-cuphon,cuphon);strcpy(merory-cmphon,cmphon);strcpy(merory-cqq,cqq);strcpy(merory-cbday,cbday);if(lina==NULL)return merory; linb=lina; while(linb-node!=NULL)linb=linb-node; linb-node=merory;return lina; } void OutSmary(Ps lina) //链表输出函数 {while(lina!=NULL){printf("name:%s,Phone:%s,Unit Number:%s,Phone number:%s,qq No:%s,Date of Birth:%s\n",lina-cname,lina-cphon,lina-cuphon,lina-cmphon,lina-cqq,lina-cbday);lina=lina-node;} }
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流