Not sure how to get rid of the spaces at the end. Thanks for any help learn.zybo
ID: 3908112 • Letter: N
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) { iExplanation / Answer
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 ",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;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.