How can I remove the preceding '0' from number 10 above? Only numbers 1-9 should have preceding '0'.
SAMPLE INPUT: 40
SAMPLE OUTPUT: 01.02.03.04.05.06.07.08.09.10 11.12.13.14.15.16.17.18.19.20 21.22.23.24.25.26.27.28.29.30 31.32.33.34.35.36.37.38.39.40
MY CODE'S OUTPUT: 01.02.03.04.05.06.07.08.09.010 011.012.013.014.015.016.017.018.019.020 021.022.023.024.025.026.027.028.029.030 031.032.033.034.035.036.037.038.039.040
Can you help me, please? I tried different ways but still won't work. I'm new in programming btw, that's why I don't know much.
Here's my code:
#include <iostream>
using namespace std;
int main()
{
int a, b;
cin >> b;
if (b > 100){
cout << "OUT OF RANGE";
}
else {
for (int a = 1; a <= b; a ){
cout << "." << "0" << a;
}
}
}
CodePudding user response:
std::cout <<"." << std::setfill('0') << std::setw(2) << a;