一、找出最长的字符串
#include "stdio.h"#include "string.h"int main(){ int i; char sx[5],smax[5]; printf("输入五个字符串:"); for(i=0;i<5;i++){ scanf("%s",sx); if(strlen(sx)>strlen(smax)){ strcpy(smax,sx); } } printf("max is %s\n",smax); return 0;}
二、分类统计字符个数
#include#include int main(){ char sc[80]; int LETTER,letter,blank,digit,other,i; LETTER=letter=0; digit=blank=other=0; printf("输入一行文字:"); gets(sc); i=0; while(sc[i]!='\0'){ if('A'<=sc[i]&&'Z'>=sc[i]) LETTER++; else if(sc[i]>='a'&&sc[i]<='z') letter++; else if(sc[i]>='0'&&sc[i]<='9') digit++; else if(sc[i]==' ') blank++; else other++; i++; } printf("LETTER=%d,letter=%d,digit=%d,blank=%d,other=%d\n",LETTER,letter,digit,blank,other); return 0;}
三、学生信息管理系统
#include "stdio.h"#include "string.h"struct students_list{ int xuehao; char name[10]; float chengji1,chengji2,chengji3; float ave;};int Count=0;void new_student(struct students_list students[],int n);void print_student(struct students_list students[]);void search_student(struct students_list students[],char *name);void average_student(struct students_list students[],char *name);int main(){ int choice,n; char name[10]; struct students_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: printf("请输入学生个数:"); scanf("%d",&n); new_student(students,n); break; case 2: print_student(students); break; case 3: printf("请输入要查找的学生姓名:"); scanf("%s",name); average_student(students,name); break; case 4: printf("请输入要查找的学生姓名:"); scanf("%s",name); search_student(students,name); break; case 0: break; } }while(choice!=0); printf("谢谢使用学生信息管理系统!\n"); return 0;}void new_student(struct students_list students[],int n){ int i; if(Count>50){ printf("系统已满!\n"); return; } printf("请输入%d个学生的学号、姓名、成绩1、成绩2、成绩3\n",n); for(i=Count;i
四、冒泡排序法
#includevoid sort(int a[80],int n){ int i,j,t; for(i=0;i a[j]){ t=a[i]; a[i]=a[j]; a[j]=t; } } }}int main(){ int a[80],n,i; printf("输入一个整数n:"); scanf("%d",&n); printf("输入%d个数:",n); for(i=0;i
五、报数游戏
#includevoid CountOff(int n,int m,int out[]){ int i,a[80],j=0,k=0; for(i=0;i