Question

Print numbers 0, 1, 2, ..., userNum as shown, with each number indented by that number...

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



Sample program:

#include <stdio.h>

int main(void) {
   int userNum  = 0;
   int i = 0;
   int j = 0;

   <STUDENT CODE>

   return 0;
}

2)

Given variables numRows and numCols (type int, already initialized), print a list of all seats in a theater. Rows are numbered, columns lettered, as in 1A or 3E. Variables already defined for your use are: int currRow, int currCol, and char currColLet. Print a space after each seat, including the last. Example output for numRows = 2 and numCols = 3:

1A 1B 1C 2A 2B 2C 
0 0
Add a comment Improve this question Transcribed image text
Answer #1

for(i=0; i<=(userNum); i++){
       for(j=1; j<=i; j++)
       cout << " ";
       cout << i << endl;
   }

Add a comment
Answer #2

Note: Program is implemented in C and CPP also.

Program:

Complete program in C:

1 #include <stdio.h> 2 int main(void) 4 5 int userNum-e int i- 0; printf(Enter your number: ; scanf(%, &userNum); //repeat

Complete program in CPP:

1 #include iostream» 2 using namespace std; 3 int main(void) 5 6 7 8 9 10 int userNum-0 int i- 0; int j = 0; cout Enter your

Sample output:

Enter your number: 3 1 2 3 sh-4.39

Code to copy:

In C:

#include
int main(void)
{
   int userNum = 0;
   int i = 0;
   int j = 0;
   printf("Enter your number: ");
   scanf("%d",&userNum);
   //repeat until i exceeds userNum
   for(i=0;i<=userNum;i++)
   {
       //print i number of spaces
       for(j=0;j        {
           printf(" ");
       }
       //print number and new line
       printf("%d\n",i);
   }
    return 0;
}

In CPP:

#include
using namespace std;
int main(void)
{
   int userNum = 0;
   int i = 0;
   int j = 0;
   cout << "Enter your number: ";
   cin >> userNum;
   //repeat until i exceeds userNum
   for (i = 0; i <= userNum; i++)
   {
       //print i number of spaces
       for (j = 0; j        {
           cout << " ";
       }
       //print number and new line
       cout << i << endl;
   }
   return 0;
}

Know the answer?
Add Answer to:
Print numbers 0, 1, 2, ..., userNum as shown, with each number indented by that number...
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
  • Print numbers 0, 1, 2, ..., userNum as shown, with each number indented by that number...

    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

  • Print numbers 0,1,2,userNum as shown, with each number indented by that number of spaces

    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 user Num = 3 prints: 

  • 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...

  • HALLENGE 4.6.1: Nested loops: Indent text ACTINITY Print numbers 0, 1,2, userNum as shown, with each...

    HALLENGE 4.6.1: Nested loops: Indent text ACTINITY 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 newine. Hint Use i and jas loop variables (initialize i and j explicitly). Note: Avoid any other spaces like spaces after the printed number. Exc userNum 3 prints 0 2

  • 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...

  • C code Given numRows and numColumns, print a list of all seats in a theater. Rows...

    C code Given numRows and numColumns, print a list of all seats in a theater. Rows are numbered, columns lettered, as in 1A or 3E. Print a space after each seat, including after the last. Ex: numRows = 2 and numColumns = 3 prints: 1A 1B 1C 2A 2B 2C #include <stdio.h> int main(void) { int numRows; int numColumns; int currentRow; int currentColumn; char currentColumnLetter; scanf("%d", &numRows); scanf("%d", &numColumns); /* Your solution goes here */ printf("\n"); return 0; }

  • Given numRows and numColumns, print a list of all seats in a theater. Rows are numbered,...

    Given numRows and numColumns, print a list of all seats in a theater. Rows are numbered, columns lettered, as in 1A or 3E. Print a space after each seat, including after the last. Ex: numRows = 2 and numColumns = 3 prints: 1A 1B 1C 2A 2B 2C c++. #include <iostream> using namespace std; int main() { int numRows; int numColumns; int currentRow; int currentColumn; char currentColumnLetter; cin >> numRows; cin >> numColumns; cout << endl; return 0; }

  • C++ Given numRows and numColumns, print a list of all seats in a theater. Rows are...

    C++ Given numRows and numColumns, print a list of all seats in a theater. Rows are numbered, columns lettered, as in 1A or 3E. Print a space after each seat, including after the last. Ex: numRows = 2 and numColumns = 3 prints: 1A 1B 1C 2A 2B 2C #include <iostream> using namespace std; int main() { int numRows; int numColumns; int currentRow; int currentColumn; char currentColumnLetter; cin >> numRows; cin >> numColumns; /* Your solution goes here */ cout...

  • (Java Zybooks) Given numRows and numColumns, print a list of all seats in a theater. Rows are numbered, columns lettered, as in 1A or 3E. Print a space after each seat, including after the last. Use s...

    (Java Zybooks) Given numRows and numColumns, print a list of all seats in a theater. Rows are numbered, columns lettered, as in 1A or 3E. Print a space after each seat, including after the last. Use separate print statements to print the row and column. Ex: numRows = 2 and numColumns = 3 prints: 1A 1B 1C 2A 2B 2C import java.util.Scanner; public class NestedLoops { public static void main (String [] args) { Scanner scnr = new Scanner(System.in); int...

  • In Java; Given numRows and numColumns, print a list of all seats in a theater. Rows...

    In Java; Given numRows and numColumns, print a list of all seats in a theater. Rows are numbered, columns lettered, as in 1A or 3E. Print a space after each seat, including after the last. Use separate print statements to print the row and column. Ex: numRows = 2 and numColumns = 3 prints: 1A 1B 1C 2A 2B 2C import java.util.Scanner; public class NestedLoops { public static void main (String [] args) { Scanner scnr = new Scanner(System.in); int...

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