m0_59671005
2021-06-25 00:17
采纳率: 100%
浏览 12

c语言问题 求祝大家

假定每个学生的信息由学号(num)、姓名(name)、语文成绩(chinese)、数学成绩(math)和英语成绩(english)构成,请编程定义学生信息结构体数组,在main函数中由键盘输入10名学生的成绩,然后定义函数calculate以计算各位学生的平均成绩、总成绩,并输出平均成绩最高的学生所有信息。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • CSDN专家-link 2021-06-25 05:49
    已采纳

    很差劲的代码块功能啊。预览都OK,为啥提交后都变了呢???

    点赞 评论
  • 
    <span class="hljs-meta">#<span class="hljs-keyword">define</span> N 2</span>
    <span class="hljs-keyword">struct</span> <span class="hljs-title class_">Student</span>
    {
        <span class="hljs-comment">//学号</span>
        <span class="hljs-type">int</span>        num; <span class="hljs-comment">//成员变量或者一个数据项</span>
        <span class="hljs-comment">//姓名</span>
        <span class="hljs-type">char</span>    name[<span class="hljs-number">20</span>];
        <span class="hljs-comment">//性别</span>
        <span class="hljs-type">char</span>    sex; <span class="hljs-comment">//M,F</span>
        <span class="hljs-comment">//成绩</span>
        <span class="hljs-type">float</span>    html;    
        <span class="hljs-type">float</span>    ppt;
        <span class="hljs-type">float</span>    cyuyan;
        <span class="hljs-type">float</span>    sum;
    }st[N];
    <span class="hljs-function"><span class="hljs-type">void</span> <span class="hljs-title">input</span><span class="hljs-params">()</span></span>;
    <span class="hljs-function"><span class="hljs-type">void</span> <span class="hljs-title">display</span><span class="hljs-params">()</span></span>;
    <span class="hljs-function"><span class="hljs-type">void</span> <span class="hljs-title">main</span><span class="hljs-params">()</span>
    </span>{
        <span class="hljs-built_in">input</span>();
        <span class="hljs-built_in">display</span>();
    }
    <span class="hljs-comment">//输入函数</span>
    <span class="hljs-function"><span class="hljs-type">void</span> <span class="hljs-title">input</span><span class="hljs-params">()</span>
    </span>{
        <span class="hljs-type">int</span> i;
        <span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>;i<N;i++)
        {
            <span class="hljs-built_in">printf</span>(<span class="hljs-string">"请输入第%d个学生的学号,姓名,性别,html,ppt,cyuyan:"</span>,i+<span class="hljs-number">1</span>);
            <span class="hljs-built_in">scanf</span>(<span class="hljs-string">"%d"</span>,&st[i].num);
            <span class="hljs-built_in">scanf</span>(<span class="hljs-string">"%s "</span>,st[i].name);
            <span class="hljs-built_in">scanf</span>(<span class="hljs-string">"%c "</span>,&st[i].sex);
            <span class="hljs-built_in">scanf</span>(<span class="hljs-string">"%f"</span>,&st[i].html);
            <span class="hljs-built_in">scanf</span>(<span class="hljs-string">"%f"</span>,&st[i].ppt);
            <span class="hljs-built_in">scanf</span>(<span class="hljs-string">"%f"</span>,&st[i].cyuyan);
            st[i].sum = st[i].html+st[i].ppt+st[i].cyuyan;
        }
            
    }
    <span class="hljs-comment">//输出</span>
    <span class="hljs-function"><span class="hljs-type">void</span> <span class="hljs-title">display</span><span class="hljs-params">()</span>
    </span>{
        <span class="hljs-type">int</span> i;
        <span class="hljs-built_in">printf</span>(<span class="hljs-string">"学号\t姓名\t\t性别\thtml\tppt\tC语言\t总分\t平均分\n"</span>);    
        <span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>;i<N;i++)
        {
            <span class="hljs-built_in">printf</span>(<span class="hljs-string">"%d\t%s\t%c\t%0.2f\t%0.2f\t%0.2f\t%0.2f\t%0.2f\n"</span>,st[i].num,st[i].name,st[i].sex,st[i].html,st[i].ppt,st[i].cyuyan,st[i].sum,st[i].sum/<span class="hljs-number">3</span>);
        }    
    }
    
    点赞 评论
  • CSDN专家-link 2021-06-25 06:16
    <span class="hljs-keyword">typedef</span> <span class="hljs-keyword">struct</span> <span class="hljs-title class_">_student</span>
    {
        <span class="hljs-type">int</span> num;
        <span class="hljs-type">char</span> name[<span class="hljs-number">20</span>];
        <span class="hljs-type">float</span> chn;
        <span class="hljs-type">float</span> maths;
        <span class="hljs-type">float</span> eng;
        <span class="hljs-type">float</span> total;
        <span class="hljs-type">float</span> avg;
    }student;
    
    <span class="hljs-function"><span class="hljs-type">void</span> <span class="hljs-title">input</span><span class="hljs-params">(student *stu,<span class="hljs-type">int</span> n)</span>
    </span>{
        <span class="hljs-type">int</span> i;
        <span class="hljs-built_in">printf</span>(<span class="hljs-string">"请逐行输入%d个学生信息:"</span>,n);
        <span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>;i<n;i++)
        {
           <span class="hljs-built_in">scanf</span>(<span class="hljs-string">"%d %s %f %f %f"</span>,&stu[i].num,stu[i].name,&stu[i].chn,&stu[i].maths,&stu[i].eng);
        }
    }
    
    <span class="hljs-function"><span class="hljs-type">void</span> <span class="hljs-title">calculate</span><span class="hljs-params">(student *stu,<span class="hljs-type">int</span> n)</span>
    </span>{
        <span class="hljs-keyword">for</span>(<span class="hljs-type">int</span> i=<span class="hljs-number">0</span>;i<n;i++)
        {
            stu[i].total =  stu[i].chn + stu[i].maths + stu[i].eng;
            stu[i].avg = stu[i].total/<span class="hljs-number">3</span>;
        }
    }
    
    <span class="hljs-function"><span class="hljs-type">void</span> <span class="hljs-title">print</span><span class="hljs-params">(student *stu,<span class="hljs-type">int</span> n)</span>
    </span>{
        <span class="hljs-type">int</span> maxpos = <span class="hljs-number">0</span>;
        <span class="hljs-keyword">for</span>(<span class="hljs-type">int</span> i=<span class="hljs-number">1</span>;i<n;i++)
        {
            <span class="hljs-keyword">if</span>(stu[i].avg > stu[maxpos].avg)
                maxpos = i;
        }
        <span class="hljs-built_in">printf</span>(<span class="hljs-string">"平均成绩最高的学生信息如下:\n"</span>);
        <span class="hljs-built_in">printf</span>(<span class="hljs-string">"学号:%d\n姓名:%s\语文:%.1f\n数学:%.1f\n英语:%.1f\n总分:%.1f\n平均分:%.1f\n"</span>,
               stu[maxpos].num,stu[maxpos].name,stu[maxpos].chn,stu[maxpos].maths,stu[maxpos].eng,stu[maxpos].total,stu[maxpos].avg);
    }
    
    <span class="hljs-type">int</span> main
    {
        student stu[<span class="hljs-number">10</span>];
        <span class="hljs-built_in">input</span>(stu,<span class="hljs-number">10</span>);
        <span class="hljs-built_in">calculate</span>(stu,<span class="hljs-number">10</span>);
        <span class="hljs-built_in">print</span>(stu,<span class="hljs-number">10</span>);
        
        <span class="hljs-keyword">return</span> <span class="hljs-number">0</span>;
    }
    
    点赞 评论

相关推荐 更多相似问题