Coding Practice

Encapsulate the triangle printing program into a function called printTriangle. Generalize it so that it takes a parameter int n to generate a nxn triangle. Select the Parsonsprob tab for hints for the construction of the code. Call your function in main with an input of 4, which should result in the following output:

*
**
***
****

Encapsulate the triangle printing program into a function called printTriangle. Generalize it so that it takes a parameter int n to generate a nxn triangle. Use the lines to construct the code, then go back to complete the Activecode tab. Call your function in main with an input of 4, which should result in the following output:

*
**
***
****

Write a function called printNumPyramid that prints out an n x n number pyramid. An example is shown below with n equal to 5. Your code should use while loops. Select the Parsonsprob tab for hints for the construction of the code. (Hint: similar to the previous question, if you want the output to look nice, using conditionals that print different amounts of spaces.)

    1
   222
  33333
 4444444
555555555

Write a function called printNumPyramid that prints out an n x n number pyramid. An example is shown below with n equal to 5. Your code should use while loops. Use the lines to construct the code, then go back to complete the Activecode tab. (Hint: similar to the previous question, if you want the output to look nice, using conditionals that print different amounts of spaces.)

    1
   222
  33333
 4444444
555555555

Write the function printAddTable which takes an int n as a parameter and prints out a nxn addition table. Call your function in main with “10” as the argument. Select the Parsonsprob tab for hints for the construction of the code. Your output should look like this:

0       1       2       3       4       5       6       7       8       9       10
1       2       3       4       5       6       7       8       9       10      11
2       3       4       5       6       7       8       9       10      11      12
3       4       5       6       7       8       9       10      11      12      13
4       5       6       7       8       9       10      11      12      13      14
5       6       7       8       9       10      11      12      13      14      15
6       7       8       9       10      11      12      13      14      15      16
7       8       9       10      11      12      13      14      15      16      17
8       9       10      11      12      13      14      15      16      17      18
9       10      11      12      13      14      15      16      17      18      19
10      11      12      13      14      15      16      17      18      19      20

Write the function printAddTable which takes an int n as a parameter and prints out a nxn addition table. Call your function in main with “10” as the argument. Use the lines to construct the code, then go back to complete the Activecode tab. Your output should look like this:

0       1       2       3       4       5       6       7       8       9       10
1       2       3       4       5       6       7       8       9       10      11
2       3       4       5       6       7       8       9       10      11      12
3       4       5       6       7       8       9       10      11      12      13
4       5       6       7       8       9       10      11      12      13      14
5       6       7       8       9       10      11      12      13      14      15
6       7       8       9       10      11      12      13      14      15      16
7       8       9       10      11      12      13      14      15      16      17
8       9       10      11      12      13      14      15      16      17      18
9       10      11      12      13      14      15      16      17      18      19
10      11      12      13      14      15      16      17      18      19      20

Write a program that uses a while loop to print out the alphabet from ‘a’ to ‘z’. Select the Parsonsprob tab for hints for the construction of the code.

Write a program that uses a while loop to print out the alphabet from ‘a’ to ‘z’. Use the lines to construct the code, then go back to complete the Activecode tab.

Write a function called factorial which takes an int n as a parameter and returns n factorial. Remembers that a factorial (denoted by !) is the product of all positive integers less than or equal to n, so 4! is 24. Use a while loop. Run and test your code! Select the Parsonsprob tab for hints for the construction of the code.

Write a function called factorial which takes an int n as a parameter and returns n factorial. Remembers that a factorial (denoted by !) is the product of all positive integers less than or equal to n, so 4! is 24. Use a while loop. Run and test your code! Use the lines to construct the code, then go back to complete the Activecode tab.

You have attempted of activities on this page