Hey cplusplus world,
I'm new to this forum and am currently studying computer science where I've taking a very huge liking too. Although, a lot of classes are online and hard to get feedback from my professor at times without physically going up to the school and hoping he is here.
I'm not asking anybody to do any of the problems I post, just simply help me with what I'm doing wrong. Thank you.
Here is my instruction:
Print numbers 0, 1, 2, ..., userNum as shown, with each number indented by that number of spaces. For each printed line, print the leading spaces, then the number, and then a newline. Hint: Use i and j as loop variables (initialize i and j explicitly). Note: Avoid any other spaces like spaces after the printed number. Ex: userNum = 3 prints:
0
1
2
3
( these are suppose to have a space concurrent to the number, i.e. One space for 1, two for 2, etc. I don't know why it isn't showing correctly on here. )
I got it to finally start printing in the form I want, but I get like 3 or 4 extra whitespaces on a new line under the 3 and can't figure it out, if somebody can help me it would be much appreciated.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
#include <stdio.h>
int main(void) {
int userNum = 0;
int i = 0;
int j = 0;
while (i <= userNum ){
printf("%i\n", i);
++i;
for (j = 0; j != i && i && j <userNum; ++j ){
printf(" ");
}
}
return 0;
}
|