0
#include <iostream>
using namespace std;
int main() {
    int n, i;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        if (i == 6 || i == 9)
            continue;
        cout << i << " ";

    }

    return 0;
}

Question- write 1 to n integer numbers but she do not write 6 and 9. you required to write a cpp program using "if" and "for" loop concepts and help to sakshi. Input Method: Get "n" which is the input number. Output Method: Print the integer value without 6 and 9.

TEST CASE 1:

INPUT
11
OUTPUT
1 2 3 4 5 7 8 10 11

My output:

1 2 3 4 5 7 8 10 11

I am getting one extra space after this 11 how to stop that? This program is printing one extra space in the output

user4581301
  • 33,082
  • 7
  • 33
  • 54

1 Answers1

1

Use the method @ user4581301 has mentioned

if (n > 0) std::cout << 1;

for(int i=2;i<n;i++)
{

    if( i == 6 || i == 9 )
        continue; 
  
    cout<<" " << i;
   
}
asmmo
  • 6,922
  • 1
  • 11
  • 25