Exercises
1. Write a program to generate and display a table of n and n2, for integer values of n ranging from 1 through 10. Be sure to print the appropriate column headings.
2. A triangular number can also be generated for any integer value of n by this formula:
triangularNumber = n (n + 1) / 2
For example, the 10th triangular number, 55, can be calculated by substituting 10 as the value for n into the previous formula. Write a program that generates a table of triangular numbers using the previous formula. Have the program generate every fifth triangular number between 5 and 50 (that is, 5, 10, 15, ..., 50).
3. The factorial of an integer n, written n!, is the product of the consecutive integers 1 through n. For example, 5 factorial is calculated ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access