使用模数运算符将秒转换为分钟和秒:%

#include stdio.h#define SEC_PER_MIN 60// seconds in a minuteint main(void){int sec, min, left;

编程学习网为您整理以下代码实例,主要实现:使用模数运算符将秒转换为分钟和秒:%,希望可以帮到各位朋友。

#include <stdio.h>

#define SEC_PER_MIN 60            // seconds in a minute

int main(voID){
    int sec, min, left;

    printf("Enter the number of seconds (<=0 to quit):\n");
    scanf("%d", &sec);            
    while (sec > 0)
    {
        min = sec / SEC_PER_MIN;  // truncated number of minutes
        left = sec % SEC_PER_MIN; // number of seconds left over
        printf("%d seconds is %d minutes, %d seconds.\n", sec, min, left);
        printf("Enter next value (<=0 to quit):\n");
        scanf("%d", &sec);
    }
    printf("Done!\n");

    return 0;
}
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐