#include<iostream>
using namespace std;
int main(){
const int x=60;
const int y=24;
int,seconds,mintutes,hours,days;
long long secondss;
cout<<"enter the number of seconds"<<endl;
cin>>secondss;
seconds=secondss%x;
int a,b;
a = secondss/x;
mintutes= a%x;
b=a/x;
hours= b%y;
cout<<secondss<<"second=";
cout<<days<<"days"<<hours<<"hours";
cout<<mintutes<<"mintutes";
cout<<seconds<<"seconds"<<endl;
return 0;
}
这里是第三章处理数据编程练习的,第四题题目是编写一个程序,要求用户以整数的方式输入秒数,使用long或long long变量储存,然后以天小时分钟和秒的方式显示这段时间,使用符号常量来表示每天有多少小时,每小时有多少分钟以及每分钟有多少秒,该程序的输入应与下面类似,enter the number of seconds,31600000
31600000Seconds等于365 dayS 17 horse 46Minutes30 SEconds
好,我们一起来看这个程序,首先呢,我们要用一个浪浪变量,也就是secondss来储存用户输入的这个秒数,然后我们再建立五个变量,通过运算方法求出多少秒,多少天?多少时?多少分?然后再用cout进行输出就可以特别要注意的是,百分号这里表示的是求余数,而不是除以的意思另外,如果想要增强程序的趣味性,那么可以在return 0前面补上一个if引导的条件状语从句也就是如果这个days大于365天就输出真长如果这个得是小于365天,也就是一年,那么就输出真短,这就是今天的代码,谢谢大家关注,我下期更精彩.