关于结构体定义时初始化及结合数组使用问题 示例

来源:互联网 发布:刀剑乱舞刷图软件 编辑:程序博客网 时间:2024/05/17 05:53

#import <Foundation/Foundation.h>


typedef struct Student

{

   int num;

   char name[20];

   double score[3];

    

}student;



int main(int argc,constchar * argv[])

{


    @autoreleasepool {

        

        // insert code here...

        NSLog(@"Hello, World!");

        

       student stu1,stu2,stu3,stu4,stu5;   


       student stu[5] = {stu1,stu2,stu3,stu4,stu5};

       

        printf("请输入5个学生的信息:\n");

       for (int i =0; i<2; i++)

        {

           scanf("%d",&stu[i].num);

           scanf("%s",stu[i].name);

           scanf("%lf%lf%lf",&stu[i].score[0],&stu[i].score[1],&stu[i].score[2]);

        }

        

       for (int i =0; i<2; i++)

        {

           printf ("%d\n",stu[i].num);

           printf ("%s\n",stu[i].name);

           printf ("%lf\n%lf\n%lf\n",stu[i].score[0],stu[i].score[1],stu[i].score[2]);

        }


    }

   return0;

}



原创粉丝点击