瓦力


私信TA

用户名:wang2012jx

访问量:13255

签 名:

三十入门

等  级
排  名 485
经  验 4523
参赛次数 3
文章发表 42
年  龄 0
在职情况 在职
学  校 清华大学
专  业

  自我简介:

题目描述

现有有N个学生的数据记录,每个记录包括学号、姓名、三科成绩。 编写一个函数input,用来输入一个学生的数据记录。 编写一个函数print,打印一个学生的数据记录。 在主函数调用这两个函数,读取N条记录输入,再按要求输出。 N<100

输入

学生数量N占一行 每个学生的学号、姓名、三科成绩占一行,空格分开。

输出

每个学生的学号、姓名、三科成绩占一行,逗号分开。

样例输入

2

a100 clang 70 80 90

b200 dotcpp 90 85 75

样例输出

a100,clang,70,80,90

b200,dotcpp,90,85,75

解题思路:

注意事项:

参考代码:

#include<stdio.h>

typedef struct student
{
    char id[10];
    char name[10];
    int score[3];
}Stu;

int main()
{
    void input(int n,Stu stu[]);
    void print(int n,Stu stu[]);
    int n;
    scanf("%d",&n);
    Stu stu[n];
    input(n,stu);
    print(n,stu);
    
    return 0;
}

void input(int n,Stu stu[])
{
//    Stu *p=stu;
    int i;
    for(i=0;i<n;i++)
    scanf("%s%s%d%d%d",&stu[i].id,&stu[i].name,&stu[i].score[0],&stu[i].score[1],&stu[i].score[2]);
    return;
}

void print(int n,Stu stu[])
{
    int i;
    for(i=0;i<n;i++)
    printf("%s,%s,%d,%d,%d\n",stu[i].id,stu[i].name,stu[i].score[0],stu[i].score[1],stu[i].score[2]);

    return;
}


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区