找出最长的字符串
分类统计字符个数
#include<stdio.h> int main() { int a,zm=0,kg=0,sz=0,qt=0; while((a=getchar())!=' ') { if((a>='A'&&a<='Z')||(a>='a'&&a<='z')) zm++; else if(a==' ') kg++; else if(a>='0'&&a<='9') sz++; else qt++; } printf("英文字母的个数:%d ",zm); printf("空格的个数:%d ",kg); printf("数字的个数:%d ",sz); printf("其他字符的个数:%d ",qt); return 0; }
学生信息管理系统
#include<stdio.h> #include<string.h> struct students_list{ char name[10]; int chinese,math,english; char ID[13]; double average; }; int Count=0; void new_student(struct students_list students[]); void search_student(struct students_list students[],char *name); void print_student(struct students_list students[]); int main() { int choice; char name[10]; struct students_list students[50]; do{ printf("******学生信息查询****** "); printf(" 1:输入 "); printf(" 2:查询 "); printf(" 3:输出 "); printf(" 0:退出 "); 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: 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.ID); students[Count]=f; Count++; } void search_student(struct students_list students[],char *name) { int i,flag=0; if(Count==0){ printf("学生信息列表是空的! "); return; } for(i=0;i<Count;i++) if(strcmp(name,students[i].name)==0){ flag=1; break; } if(flag){ printf("姓名:%s ",students[i].name); printf("语文成绩:%d ",students[i].chinese); printf("数学成绩:%d ",students[i].math); printf("英语成绩:%d ",students[i].english); printf("平均成绩:%.2lf ",students[i].average=(students[i].chinese+students[i].math+students[i].english)/3.0); printf("学号:%s ",students[i].ID); } else printf("无此学生信息!"); } 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].ID); } }
分类统计字符个数方法二
#include<stdio.h> int main() { int digit,capital,letter,blank,other; char s[80]; int i; digit=capital=letter=blank=other=0; printf("Enter characters:"); gets(s); i=0; while(s[i]!='