Chapter 8

Chapter 8 Code Examples

MATLAB Code Examples

 

Python Code Examples

Exercises

  1. Write a for loop that prints all integers from 1 to n.
  2. Write a for loop that prints all integers in reverse from n to 1.
  3. Write a while loop that prints all even numbers from 1 to 100.
  4. Write a while loop that prints all integers in reverse from n to 1.
  5. Write a loop that calculates the factorial of n (n! – the product of all positive integers less than or equal to n).