当前位置:网站首页>Exercise 9-1 time conversion (15 points)
Exercise 9-1 time conversion (15 points)
2022-06-11 22:25:00 【Xiaoyan y】
This question requires the preparation of procedures , With hh:mm:ss Output in the format of... After a given time n Time value after seconds ( exceed 23:59:59 From 0 The clock starts at ).
Input format :
Enter in the first line with hh:mm:ss The format of gives the start time , The second line gives the number of whole seconds n(<60).
Output format :
The output is given on one line hh:mm:ss Result time in format .
sample input :
11:59:40
30
sample output :
12:00:10
#include<stdio.h>
struct time{
int hour;
int minute;
int second;
};
int main(){
struct time t;
int sec,t1;
scanf("%d:%d:%d",&t.hour,&t.minute,&t.second);
scanf("%d",&sec);
t1=sec+t.second;
if(t1>=60){ // Seconds greater than or equal to 60, Carry forward
t.second=t1-60;
t.minute++;
if(t.minute>=60){ // Minutes are greater than or equal to 60, Carry forward
t.minute=t.minute-60;
t.hour++;
if(t.hour>=24){
t.hour-=24;
}
}
}else{
t.second=t1;
}
printf("%02d:%02d:%02d",t.hour,t.minute,t.second);
}summary :
- As long as the clock is clear 、 minute 、 The problem of carry between seconds , It can be easily solved ;
- Pay attention to the output format , use “%02d” To output .
边栏推荐
猜你喜欢

If I take the college entrance examination again, I will study mathematics well!

Prefabricated dishes in the trillion market have also begun to roll inside. How can brands stand out in the fierce competition?

MySQL事务简介

超标量处理器设计 姚永斌 第2章 Cache --2.2 小节摘录

机器学习之Logistic回归简单实例

win10字体模糊怎么调节

学1个月爬虫就月赚6000?别被骗了,老师傅告诉你爬虫的真实情况

Glory earbud 3 Pro with three global first strong breakdowns flagship earphone Market

360 online enterprise security cloud is open to small, medium and micro enterprises for free

Simple example of logistic regression for machine learning
随机推荐
Glory earbud 3 Pro with three global first strong breakdowns flagship earphone Market
360 online enterprise security cloud is open to small, medium and micro enterprises for free
超標量處理器設計 姚永斌 第2章 Cache --2.4 小節摘錄
Sword finger offer array question type summary
Regular execution of shell scripts in crontab
Non recursive writing of quick sort
习题8-8 判断回文字符串 (20 分)
Tkinter study notes (III)
Zhanrui IOT chip 8910dm is certified by Deutsche Telekom
二叉树的基本操作与题型总结
点云读写(二):读写txt点云(空格分隔 | 逗号分隔)
每日一题-1317. 将整数转换为两个无零整数的和
【Uniapp 原生插件】商米钱箱插件
Win10弹出USB时出现该设备正在使用的解决方法
win10字体模糊怎么调节
[Matlab]二阶节约响应
C language implements eight sorts of sort merge sort
Addition without addition, subtraction, multiplication, Division
Dynamic memory management (1)
SequenceList顺序表的实现