题解 | #牛牛的水杯#

牛牛的水杯

https://www.nowcoder.com/practice/c196c47c23394bf3bdd4f82a838df6bf

#include <stdio.h>

int main() {

    int h, r;//定义杯子的高度和半径
    float total = 10000;//牛牛每天喝10L水,也就是10000ml

    scanf("%d %d", &h, &r);//输入杯子的高度和半径

    float v = 0;
    v = 3.14 * h * r * r;//体积的公式
    
    int bottle = total / v;//喝多少瓶
    float decision = total / v - bottle;//用来判定有没有完整的喝完一瓶

    if (decision == 0)//完整的喝完
    {
        printf("%d\n", bottle);
    }
    else //最后一瓶没有完全喝完
    {
        printf("%d\n", bottle + 1);
    }
    
    return 0;
}

#c语言基础#
C语言基础 文章被收录于专栏

里面较为详细的介绍了c语言的相关用法和有关题目。

全部评论

相关推荐

昨天 13:37
重庆大学 C++
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务