第十二次作业
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第十二次作业相关的知识,希望对你有一定的参考价值。
#include<stdio.h> #include<string.h> int main() { int i,max; char sx[20]; for(i=0;i<5;i++){ gets(sx); if(i>0) max=strcmp(sx-1,sx); } if(max==-1) printf("%s",sx); return 0; }
#include<stdio.h> #include<string.h> int main() { char sx[20]; int i,big,small,num,blank,other; big=small=num=blank=other=0; gets(sx); for(i=0;i<strlen(sx);i++){ if(sx[i]>=‘A‘&&sx[i]<=‘Z‘) big++; else if(sx[i]>=‘a‘&&sx[i]<=‘z‘) small++; else if(sx[i]>=‘0‘&&sx[i]<=‘9‘) num++; else if(sx[i]==‘ ‘) blank++; else other++; } printf("大写字母有%3d个\n小写字母有%3d个\n空格有%3d个\n数字有%3d个\n其他字符有%3d个\n",big,small,num,blank,other); return 0; }
#include<stdio.h> #include<string.h> struct student_list{ char name[10]; int aaa1; int aaa2; int aaa3; char number[10]; }; int count=0; void search_student(struct student_list students[],char *name); void new_student(struct student_list students[]); void printf_student(struct student_list students[]); void average_student(struct student_list students[],double average); int main() { int choice; double average; char name[10]; struct student_list students[50]; do{ printf("******学生信息管理系统*******\n"); printf("\t1:新建\n"); printf("\t2:查询\n"); printf("\t3:输出\n"); printf("\t4:平均成绩\n"); printf("\t0:退出\n"); printf("请选择功能:"); scanf("%d",&choice); switch(choice){ case 1: new_student(students); break; case 2: printf("请输入要查找的学生姓名:"); scanf("%s",name); search_student(students,name); break; case 3: printf_student(students); break; case 4: average_student(students,average); case 0: break; } }while(choice!=0); } void new_student(struct student_list students[]) { int i; struct student_list s; if(count==50) printf("学生系统数据已满!"); printf("请输入学生姓名:"); scanf("%s",s.name); printf("请输入学生学号:"); scanf("%s",s.number); printf("请输入学生三科成绩:"); scanf("%d%d%d",&s.aaa1,&s.aaa2,&s.aaa3); students[count]=s; count++; } void printf_student(struct student_list students[]) { printf("系统中学生为:"); int i; for(i=0;i<count;i++){ printf("%s %s %d %d %d",students[i].name,students[i].number,students[i].aaa1,students[i].aaa2,students[i].aaa3); } } void search_student(struct student_list students[],char *name) { int i,a=0; if(count==0){ printf("系统内无信息。"); return; } for(i=0;i<count;i++) if(strcmp(name,students[i].name)==0){ a=1; break; } if(a==1){ printf("姓名:%s\t",students[i].name); printf("学号:%s\t",students[i].number); printf("分数:%d %d %d\n",students[i].aaa1,students[i].aaa2,students[i].aaa3); } } void average_student(struct student_list students[],double average) { int i; for(i=0;i<count;i++) average=(students[i].aaa1+students[i].aaa2+students[i].aaa3)/3; printf("平均成绩=%.2lf\n",average); return; }
以上是关于第十二次作业的主要内容,如果未能解决你的问题,请参考以下文章