Question

Not sure how to get rid of the spaces at the end. Thanks for any help

learn.zybooks.com 21.7. Nested loops zyBooks My library EGR 219 home 21.7: Nested loops E zyBooks catalog Help/FAQ Dennis Roberts CAHALE.7.1: Nested loops: Indent text Print numbers 0, 1,2,. serNum 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 winclude estdio.h 1es 3 int main(void) 4int userNum; 5 int i; 6 int j; 10 for (i-0; ++i) { i<-user-Num; printfXdn,i); for j--1; ji+j) t 12 13 14 15 16 17 return 18 printf( ) Your solution goes here/ Run X Testing with userNum 3 Output is nearly correct; but whitespace differs. See highlights below. Special character legend

0 0
Add a comment Improve this question Transcribed image text
Answer #1

In first question

In the above code inner forloop placed after printing the digit so it makes i to print extra line

so modify to code following :

#include <stdio.h>

int main()
{
int userNum;
int i;
int j;
userNum=3;
for(i=0;i<=userNum;i++){
  
for(j=0;j<i;++j){ //prints the spaces before it prints number
printf(" ");
}

printf("%d\n",i); //it prints number
}

return 0;
}

input of second program:

#include <stdio.h>

int main()
{
int numRows;
int numCols;
int i;
int j;
char c;

numRows=2;
numCols=3;
for(i=1;i<=numRows;i++){ //opens the loop for rows
c='A'; //initialized column value to A for every row
for(j=1;j<=numCols;j++){ //opens the loop for columns
printf("%d%c ",i,c++); //prints the row and columns seat numbers
}
}

return 0;
}

Add a comment
Know the answer?
Add Answer to:
Not sure how to get rid of the spaces at the end. Thanks for any help...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • AT46.1: Nested loops: Indent text HALLENGE 461: Nested loops: Indent text Print numbers 0,1,2 userNum as...

    AT46.1: Nested loops: Indent text HALLENGE 461: 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 3 int noin(void){ 6 int 1- Your solution goes here 1e return...

  • For JAVA Please post code in bold. Thank you. Print numbers 0, 1, 2, ..., userNum...

    For JAVA Please post code in bold. Thank you. 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 Challenge 4.6.1: Nested loops ndent...

  • Computer Science I home> 4 8 Nested loops Feedback | 48.1 Nested loops Indent text Print...

    Computer Science I home> 4 8 Nested loops Feedback | 48.1 Nested loops Indent text Print numbers 0, 1,2userNum 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

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT