zoukankan      html  css  js  c++  java
  • 第十三次作业

    一、找出最长的字符串

    #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
    ",smax);
        
        return 0;
    }

    二、分类统计字符个数

    #include <stdio.h>
    #include <string.h>
    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]!=''){
            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
    ",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("******学生信息管理系统******
    ");
            printf("	1:输入学生基本信息
    ");
            printf("	2:输出学生基本信息
    ");
            printf("	3:计算学生平均成绩
    ");
            printf("	4:查找学生基本信息
    ");
            printf("	0:退出
    ");
            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("谢谢使用学生信息管理系统!
    ");
        
        return 0;
    }
    
    void new_student(struct students_list students[],int n)
    {
        int i;
        if(Count>50){
            printf("系统已满!
    ");
            return;
        }
        printf("请输入%d个学生的学号、姓名、成绩1、成绩2、成绩3
    ",n);
        for(i=Count;i<Count+n;i++){
            scanf("%d%s%f%f%f",&students[i].xuehao,students[i].name,&students[i].chengji1,&students[i].chengji2,&students[i].chengji3);
        }
        Count=Count+n;
    }
    
    void print_student(struct students_list students[])
    {
        printf("学生信息系统中的学生为:
    ");
        int i;
        for(i=0;i<Count;i++){
            printf("%d %s %.2f %.2f %.2f
    ",students[i].xuehao,students[i].name,students[i].chengji1,students[i].chengji2,students[i].chengji3);
        }
    }
    
    void average_student(struct students_list students[],char *name)
    {
        int i;
        if(Count==0){
            printf("该系统无学生!
    ");
            return;
        }
        printf("学生的平均成绩为:");
        for(i=0;i<Count;i++){
            students[i].ave=(students[i].chengji1+students[i].chengji2+students[i].chengji3)/3.0;
            printf("第%d个学生的平均成绩为%.2f
    ",i+1,students[i].ave);
        }
    }
    
    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].xuehao);
                printf("成绩:%.2f	",students[i].chengji1);
                printf("成绩:%.2f	",students[i].chengji2);
                printf("成绩:%.2f	",students[i].chengji3);
            }
            else
                printf("查无此人!
    ");
        
    }

    四、冒泡排序法

    #include <stdio.h> 
    void sort(int a[80],int n)
    {
        int i,j,t;
        for(i=0;i<n;i++){
            for(j=i+1;j<n;j++){
                if(a[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<n;i++){
            scanf("%d",&a[i]);
        }
        sort(a,n);
        for(i=0;i<n;i++){
            printf("%d	",a[i]);
        }
        
        return 0;
    }

    五、报数游戏

    #include<stdio.h>
    void CountOff(int n,int m,int out[])
    {
        int i,a[80],j=0,k=0;
        for(i=0;i<n;i++){
            a[i]=i+1;
        }
        while(k<n){
            for(i=0;i<n;i++){ 
                if(a[i]!=0){
                    j++;
                    if(j==m){
                        out[k]=a[i];
                        j=0;
                        k++;
                    }
                }
            }    
        }
    }
    int main()
    {
        int i,x,y,Out[80];
        printf("输入总人数n:");
        scanf("%d",&x);
        printf("输入退出次位m(m<n):");
        scanf("%d",&y);
        CountOff(x,y,Out);
        printf("退出的顺序编号:");
        for(i=0;i<x;i++){
             printf("%3d",Out[i]);
        }
        printf("
    ");
        
        return 0;
    }
  • 相关阅读:
    node
    ionic
    关于websocket和ajax无刷新
    HTML图片热区
    npm -D -S -g -i 以及安装技巧
    es6 webpack转es5
    es6
    es6
    ssh tunnel
    vim上次和下次光标位置
  • 原文地址:https://www.cnblogs.com/wojiushgedajiangyoude/p/6194635.html
Copyright © 2011-2022 走看看