3-4:编写一个程序,要求用户以正数方式输入秒数(使用long或long long变量存储),然后以天、小时、分钟和秒的方式显示这段时间。使用符号常量来表示每天有多少小时、每小时有多少分钟以及每分钟有多少秒。该程序的输出应与下面的类似:
Enter the number of seconds:31600000
31600000 seconds=365 days,17 hours,46 minutes,40 seconds
程序代码:
#include<iostream> using namespace std;
int main() { const int da_to_ho=24; const int ho_to_mi=60; const int mi_to_se=60; long s; long days,hours,minutes,seconds; cout<<"enter the number of seconds:"; cin>>s; days=s/da_to_ho/ho_to_mi/mi_to_se; hours=s%(da_to_ho*ho_to_mi*mi_to_se)/(ho_to_mi*mi_to_se); //醉醉的 当初写上一个语句是全部用的是除法 结果小于0出错 杀毒软件说我的这个程序有可能是木马哈哈哈 minutes=s%(ho_to_mi*mi_to_se)/(mi_to_se); seconds=s%(mi_to_se); cout<<s<<" seconds ="<<days<<"days,"<<hours<<"hours,"<<minutes<<"minutes,"<<seconds<<"seconds\n"; return 0; }
编写一个程序,要求用户输入全球当前的人口和美国当前的人口(或其他国家的人口)将这些信息存储在long long变量中,并让程序显示美国(或其他国家)的人口占全球人的百分比,该程序的输出应与下面类型相似: enter the world's population:6898758899
enter the population of the us:310783781
the population of the us is 4.50492% of the world population.
程序代码:
#include<iostream> using namespace std; int main() { cout.setf(ios_base::fixed,ios_base::floatfield); double us,world;//题目要求是longlong类型,可是系统不支持,只能用double来代替。 cout<<"enter the world's population: "; cin>>world; cout<<"enter the population of the us: "; cin>>us; const double n=100; double percent=us/world*n; cout<<"the population of the us is "<<percent<<"% of the world population."; return 0; }
编写一个程序,要求用户输入全球当前的人口和美国当前的人口(或其他国家的人口)将这些信息存储在long long变量中,并让程序显示美国(或其他国家)的人口占全球人的百分比,该程序的输出应与下面类型相似:
enter the world's population:6898758899
enter the population of the us:310783781
the population of the us is 4.50492% of the world population.
#include
using namespace std;
int main()
{
cout.setf(ios_base::fixed,ios_base::floatfield);
double us,world;//题目要求是longlong类型,可是系统不支持,只能用double来代替。
cout<<"enter the world's population: ";
cin>>world;
cout<<"enter the population of the us: ";
cin>>us;
const double n=100;
double percent=us/world*n;
cout<<"the population of the us is "<