——文章由 www.owhite.cn 老白啵网站爬取得到 如有侵权请及时联系站长邮箱删除
` #include<stdio.h>

void show_single()
{
    printf("**************************\n");
}
void show_txt()
{
    printf("*******防疫不放松***********\n");
}
void show_1()
{
    printf("*****************************\n");
}
int main()
{
    show_single();
    show_txt();
    show_1();
    return 0;
}

结构体变量的定义

利用sizeof运算符计算一个结构体类型的数据在内存占用的实际字节数
#include<stdio.h>
struct student
{
    int sno;
    char name[20];
    char classname[20];
    int grade[3];
}
stu1;
int main()
{
    printf("%d\n",sizeof(stu1));
    return 0;
}

结构体变量的引用

通过输入信息,输出信息

#include<stdio.h>
struct student
{
    int sno;
    char name[20];
    char classname[20];
    double grade[3];
};
int main()
{
    struct student stu1;
    printf("请输入学生信息: 学号,姓名,班级,三门课程的成绩\n");
    scanf("%d",&stu1.sno);
    scanf("%s",stu1.name);
    scanf("%s",stu1.classname);
    scanf("%lf%lf%lf",&stu1.grade[0],&stu1.grade[1],&stu1.grade[2]);
    printf("输出结构体变量stu1的信息为:\n");
    printf("学号%d\n",stu1.sno);
    printf("姓名%s\n",stu1.name);
    printf("班级:%s\n",stu1.classname);
    printf("课程1:%f\n",stu1.grade[0]);
    printf("课程2:%f\n",stu1.grade[1]);
    printf("课程2:%f\n",stu1.grade[2]);
    return 0;
}

#include<stdio.h>
struct student
{
    int sno;
    char name[20];
    char classname[20];
    double grade[3];
};
int main()
{
    struct student stu1;
    printf("请输入学生信息: 学号,姓名,班级,三门课程的成绩\n");
    scanf("%d",&stu1.sno);
    scanf("%s",stu1.name);
    scanf("%s",stu1.classname);
    scanf("%lf%lf%lf",&stu1.grade[0],&stu1.grade[1],&stu1.grade[2]);
double sum=0,avg;
    int i;
    for(i=0;i<3;i++)
    {
        sum+=stu1.grade[i];
    }
    avg=sum/3.0;
    printf("输出结构体变量stu1的信息为:\n");
    printf("学号%d\n",stu1.sno);
    printf("姓名%s\n",stu1.name);
    printf("班级:%s\n",stu1.classname);
    printf("课程1:%f\n",stu1.grade[0]);
    printf("课程2:%f\n",stu1.grade[1]);
    printf("课程2:%f\n",stu1.grade[2]);
    return 0;
}

标签: printf, int, main, return, void, show_txt, show_1

评论已关闭