Home > front end >  Remove '0' from numbers less than and equal 9
Remove '0' from numbers less than and equal 9

Time:09-28

How can I have an output of

Sample Input No.1: 9

Sample Output No.1: 1.2.3.4.5.6.7.8.9

If you input numbers less than or equal to 9, the output should be (1.2.3.4.5.6.7.8.9)

And if you input numbers greater than 9, for example:

Sample Input No.2: 20

Sample Output No.2: 01.02.03.04.05.06.07.08.09.10 11.12.13.14.15.16.17.18.19.20

My code below is for Sample Input & Output No.2. I tried adding another for loop for SAMPLE NO.1 but it still reads Sample No.2 code. What should I do?

#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
    int a, num;
    cin >> num;

    if (num > 100 || num <= 1){
        cout << "OUT OF RANGE";
    }
    else {
        for (int a = 1; a < num; a  ){
            cout << setfill('0') << setw(2) << a << ".";
        }
        cout << num;
    }

}

kind of new to programming, don't know much

  •  Tags:  
  • c
  • Related