Exercises on SLIM Programming

  1. Write a SLIM program that reads in an integer n from the user, then prints 1 if n is prime, or prints 0 if n is not prime. For example, if the user enters the number 9, your program should print 0. If the user enters the number 3, your program should print 1.
  2. Write a SLIM program that reads in a positive integer n from the user, then prints all primes not bigger than n in order of increasing size. For example, if the user enters 10, your program should print

    2  
    3
    5
    7
  3. Write a SLIM program that reads in a nonnegative integer n and prints out the nth Fibonacci number. For example, if the user enters 3, your program should print 2.
  4. Write a SLIM program that reads in a sequence of positive integers, terminated by a nonpositive number, then stores the read-in positive numbers in data memory (as an array), then sorts them, and lastly prints out the sorted array. For example, given the input numbers

    9
    2
    7
    3
    1
    0

    the program should print

    1
    2
    3
    7
    9

    You can use any sorting algorithm, e.g., bubble sort, shell sort, insertion sort, selection sort, or merge sort, etc.