CS 1425 Computer Science Overview
Practice Exercises

Create a subdirectory of your 1425 directory called "lab3". For each of the following problems, create a program in that directory using the name given in parentheses after the problem number. FIRST think about the problem to see if you can come up with your own algorithm for solving the problem. These are due by NEXT Wednesday.

  1. (p1.C) Write a program that will read in integers from the user until the user inputs a 0. At that point the program should tell the user what the number just before the 0 was. If the user inputs a 0 for his first number, the program should print the string "You had no previous number."

  2. (p2.C) Ulam's Conjecture: Start with any number, n. If n is even, divide it by 2. If n is odd, multiply it by three and add 1. Repeat this process as long as n is greater than 1. Ulam's Conjecture is that n always becomes 1 eventually. Write a loop that tests this Conjecture for a specific value of n input by the user. Print each number in the series and at the end tell how many numbers were printed.

  3. (p3.C) Print the factorials from 1 to 10. Definition of factorial, which in math is written with an exclamation mark: n! = n*(n-1)*(n-2)*...*(2)*(1)
    Your program should print something like the following (but fill in the missing lines):
    1! = 1
    2! = 2
    3! = 6
    .
    .
    .
    10! = 3628800

  4. (p4.C) Have the user enter 8 numbers from the keyboard and print out the largest of the numbers.

  5. (p5.C) Have the user enter 8 numbers from the keyboard and print out the smallest and the largest of the numbers.

  6. (p6.C) Input a positive number, n, and determine if n is prime. A prime number is one that can only be divided evenly by itself and 1.