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:
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.