11.5.cpp

来自「c入门代码大全」· C++ 代码 · 共 41 行

CPP
41 行
字号
//有一个结构体变量stu,内含学生学号,姓名和3们课程的成绩。要求在main函数中赋值,在另一个函数print中将他们输出
//今用结构体变量作函数参数
#inlcude <stdio.h>
#incude <string.h>
#define FORMAT "%d\n%s\n%f\n%f\n%f\n"
struct student
{

   int num ;
   char name[20] ;
   float score[3] ;

}  ;


int main()
{

   void print(struct student) ;
   struct student stu ;
   stu.num = 12345 ;
   strcpy(stu.name , "li") ;
   stu.score[0] = 67.5 ;
   stu.score[1] = 89 ;
   stu.score[2] = 78.6 ;
   print(stu) ;
   return 0 ;

}


int  print(struct student stu)
{

   printf(FORMAT , stu.num , stu.name , stu.score[0] , stu.score[1] , stu.score[2])
   printf("\n");
   getchar() ;
   return 0 ;
     
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?