第一题
#include<stdio.h> #include<string.h> int main() { int i; char sx[80],smax[80]; printf("请输入5个字符串: "); scanf("%s",sx); strcpy(smax,sx); for(i=1;i<5;i++) { scanf("%s",sx); if(strcpy(smax,sx)>0) strcpy(smax,sx); } printf("最长的字符串是:%s ",smax); return 0; }
第二题
#include<stdio.h> int main() { char ch; int num,word,other,kong; int i; num=word=kong=other=0; printf("请输入10字符: "); for(i=1;i<=10;i++) {scanf("%c",&ch); if(ch>='0'&&ch<='9') num++; else if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z')) word++; else if(ch==' ') kong++; else other++; } printf("num=%d,kong=%d,word=%d,other=%d ",num,word,kong,other); return 0; }
第三题
#include<stdio.h> #include<string.h> struct students_list{ char name[50],xh; int Chinese,Math,English; double average; }; int Count=0; void new_student(struct students_list students[]); void print_student(struct students_list students[]); int main() { int choice; char name[50]; struct students_list students[50]; do{ printf("******学生信息查询****** "); printf(" 1:输入 "); printf(" 2:查询 "); printf(" 3:输出 "); printf(" 0:退出 "); scanf("%d",&choice); switch(choice){ case 1: new_student(students); break; case 2: printf("请输入学生姓名:"); scanf("%s",name); break; case 3: print_student(students); break; case 0: break; } }while(choice!=0); printf("感谢您使用本系统! "); return 0; } void new_student(struct students_list students[]) { struct students_list f; if(Count==50){ printf("信息列表已满! "); return; } printf("请输入学生的姓名:"); scanf("%s",f.name); printf("请输入学生的语文成绩:"); scanf("%d",&f.Chinese); printf("请输入学生的数学成绩:"); scanf("%d",&f.Math); printf("请输入学生的英语成绩:"); scanf("%d",&f.English); printf("请输入学生的学号:"); scanf("%s",f.xh); students[Count]=f; Count++; } void print_student(struct students_list students[]) { printf("学生信息列表的学生信息如下: "); int i; for(i=0;i<Count;i++) { printf("%s %d %d %d %.2lf %s ",students[i].name,students[i].Chinese,students[i].Math,students[i].English,students[i].average,students[i].xh); } }