ACTIVITY, 4.6.1: Nested loops: Indent text. Print numbers 0, 1,2,., userNum as s
ID: 3869864 • Letter: A
Question
ACTIVITY, 4.6.1: Nested loops: Indent text. 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: 1 2 3 1 #include 3 int main void) L test passed int userNum 0; 5 int i =0; 6 int j =0; All tests passed 8 Your solution goes here 10 return ; RunExplanation / Answer
#include <stdio.h>
int main(void)
{
int userNum = 0;
int i=0;
int j=0;
userNum = 3;
for(i=0;i<=userNum;i++){
for(j=0;j<i;j++){
printf(" ");
}
if(i==j){
printf("%d ",i);
}
}
return 0;
}
Output: