zoukankan      html  css  js  c++  java
  • 四、预习检查:填空,并注释"每空"填充的依据

    1) 完成下列程序,该程序计算 10 名学生的平均成绩 

    #include <stdio.h>
    #include <string.h>
    struct student {
        int num;
        char name[20];
        int score;
    }; 
    struct student stud[10];
    int main(void)
    {
        int   i , sum = 0 ;
        for(i = 0; i < 10; i++){
            scanf("%d%s%d ",&stud[i].num,stud[i].name, &stud[i].score);
            sum += stud[i].score;
        }
        printf("aver = %d 
    ", sum/10);
        return 0;
    }

    2) 下列程序读入时间数值,将其加 1 秒后输出,时间格式为:hh: mm: ss,即小时:分钟:秒,当小时等于 24 小时,置为 0。

    #include<stdio.h>
    struct { int hour, minute, second;} time;
    int main(void)
    {
        scanf("%d: %d: %d",    &time.hour, &time.minute, &time.second );
        time.second++;
        if( time.second == 60){
            time.minute++ ; 
            time.second = 0;
            if(time.minute == 60){
                time.hour++; 
                time.minute = 0;
                if( time.hour == 24 )
                    time.hour = 0; 
            }
        }
        printf ("%d: %d: %d 
    ", time.hour, time.minute, time.second );
        return 0;
    } 

    3) 写出下面程序的运行结果,并简要描述原因。

    struct s1{
        char c1, c2;
        int   n;
    };
    struct s2{
        int n; 
        struct s1 m;
    } m = {1, {‘A’, ’B’, 2} };
    int main(void)
    { 
        printf(“%d	%d	%c	%c
    ”, m.n, m.m.n, m.m.c1, m.m.c2);
        return 0;

    1 2 A B

     4) 写出下面程序的运行结果,并简要描述原因

    struct abc{    int a;    float b;    char *c; };
    int main(void)
    {
        struct abc x = {23,98.5,"wang"};
        struct abc *px = &x;
        printf("%d, %s, %.1f, %s 
    ", x.a, x.c, (*px).b, px->c );
        return 0;
    }

    23 wang 98.5 wang

  • 相关阅读:
    搭建基于nginx-rtmp-module的流媒体服务器
    mysql length和char_length
    mediainfo使用
    linux下ftp服务器搭建
    排序算法
    设计模式之注册树模式
    dock
    linux下安装使用tar
    linux下安装rar
    linux 内存操作相关命令
  • 原文地址:https://www.cnblogs.com/blgl/p/3434826.html
Copyright © 2011-2022 走看看