首页 > 其他 > 详细

例4-2 求平均分

时间:2019-04-05 22:34:52      阅读:136      评论:0      收藏:0      [点我收藏+]

例4-2 求平均分

更改例3-3,计算平均分、统计不合格人数
程序核心——if语句

程序

#include<stdio.h>
int main()
{
    int count,num;
    double grade,total;
    
    num=total=count;
    printf("Enter grades:"); 
    scanf("%lf",&grade);
    
    while(grade>=0)
    {
        total+=grade;
        num++;
        if(grade<60)
            count++;
        scanf("%lf",&grade);
    } 
    if(num!=0)
    {
        printf("Grade average is %.2f",total/num);
        printf("Number of failures is %d",count);
    } 
    else
        printf("Grade averageis 0");
    
} 

结果

Enter grades:58 78 87 90 -1
Grade average is 78.25Number of failures is 1
--------------------------------
Process exited after 36.19 seconds with return value 0
请按任意键继续. . .

分析

重点:while语句

例4-2 求平均分

原文:https://www.cnblogs.com/5236288kai/p/10660115.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!