confusINg code in C++

Shentella's Avatar
Newbie Member
Hey guys ,I'm a beginner of C++,

I'm stuck on a perticular problem in which a user is asked to input a number less than 10.
For instance 8.

then the output will be like 1 2 3 4 5 6 7 8 6 5 4 3 2 1 get it? it will count till the input number and then count back to one.

The main issue about this problem is that everything has to be done in a If/esingle for-loop.lf/else statements are not allowed and using any extra variable outside the loop is also not allowed.
xpi0t0s's Avatar, Join Date: Aug 2004
Hint: abs.
virxen's Avatar, Join Date: Nov 2009
Pro contributor
#include <iostream>

using namespace std;

int main(){
    int i,number=11;
    while (number>=10){
        cout<<"enter a number <10:";
    for (i=-number+1;i<=number-1;i++){
        cout<<(number-abs(i))<<" ";
    return 0;