The Biggest Water Proble

The Biggest Water Problem

https://www.nowcoder.com/practice/435aa556e093463891f6da7d322140a4?tpId=290&tqId=39938&sourceUrl=https%3A%2F%2Fwww.nowcoder.com%2Fexam%2Foj%3Ftab%3D%25E8%25AF%25AD%25E6%25B3%2595%25E7%25AF%2587%26topicId%3D290

#include <stdio.h>

int main() {
    int num = 0;

    scanf("%d", &num);
    while (num >= 10) 
    {
        int sum = 0;
        while (num)
        {
            // 将num的每一位上的数字进行相加
            sum += (num % 10);
            num /= 10;
        }
        num = sum;
    }
    printf("%d", num);

    return 0;
}

全部评论

相关推荐

10-11 17:30
湖南大学 C++
我已成为0offer的糕手:羡慕
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务