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
for(i=0; i<=(userNum); i++){
for(j=1; j<=i; j++)
cout << " ";
cout << i <<
endl;
}
Note: Program is implemented in C and CPP also.
Program:
Complete program in C:
Complete program in CPP:
Sample output:
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;
}
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. 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 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 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 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 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, 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 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 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 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...