c++ - Is that possible by only using while loop? -
my tutor gave me assignment have write code contains while loop , prints:
1 2 1 3 2 1 4 3 2 1 5 4 3 2 1
i tried 100 times , failed 100 times. due limited knowledge, began think tutor messing brain. if it's possible, please introduce me code prints numbers in order. thanks...
int = 1; int limit = 5; while (i <= limit) { int j = 1; while (j <= limit -i) //loop print desired space. { cout << " "; j++; } int k = i; while(k) { cout<<k; //printing digits k--; } cout << endl; //adding new line character @ end. i++; }
say hello tutor :)
Comments
Post a Comment