using namespace std; #include <stdio.h> #include <cmath> #include <iomanip> #include <iostream> #include <cstdio> int main() { int h,m,n,s,a,b,c,k,k1,k2,abc; cin>>abc; a=(abc/3600)%24; b=(abc/60)%60%60; c=(abc%60)%60; cout<<a<<":"<<b<<":"<<c; return 0; } - 2Before asking a question, make sure you complete a thorough search for an answer. Share the result of your search and tell us what you found and why the answers you found did not suit you. This will demonstrate your ability to think for yourself, help avoid duplicate obvious answers and, most importantly, increase the chances of getting an accurate answer! - Enikeyschik
- stackoverflow.com/questions/1714515/… - HolyBlackCat
- Already did it, I can not understand how here when for example 2 you need to output 02 - Program
|
1 answer
Through std::setfill('0') set the placeholder, through std::setw(N) set the width of the output number. Anything not occupied by the number itself will be filled with a filler character.
#include <iostream> #include <iomanip> int main() { int i = 42; std::cout << std::setfill('0') << std::setw(8) << i << "\n"; } Result:
00000042
|