intmain() { usingnamespace std; long inputSeconds; int days, hours, minutes, seconds; cout << "Enter the number of seconds: "; cin >> inputSeconds; days = inputSeconds / Minute / Hour / Day; hours = (inputSeconds - days * Day * Hour * Minute) / Minute / Hour; minutes = ((inputSeconds - days * Day * Hour * Minute) - hours * Minute * Hour) / Minute; seconds = ((inputSeconds - days * Day * Hour * Minute) - hours * Minute * Hour) - minutes * Minute; cout << inputSeconds << " seconds = " << days << " days, " << hours << " hours, " << minutes << " minutes, " << seconds << " seconds!"; return0; }
CH02 Code Answer 5:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include<iostream>
intmain() { usingnamespace std; longlong worldPopulation, population; cout << "Enter the world's population: "; cin >> worldPopulation; cout << "Enter population of the China: "; cin >> population; cout << "The population of the China is " << double(population) / double(worldPopulation) * 100 << "% of the world population!"; return0; }