CSCI 151: Introduction to Computer Science - Fall 2009
Lab 2

  
Objectives:
practice with basic LINUX commands,
integer arithmetic in C;
compiling and executing C code.   
Lab 2 includes Practice Part ONLY.
Assignment part you will need to submit at the end of the lab.
Assignment part will be handed out in class after we will finish the Practice Part.
Lab Practice:

In this part you will write a few programs. We will work according to the following plan:

Important:

  • Start your program with comments part that includes:
  • In all programs you have to explain what is the meaning of the results that your program is printing. Don't print numbers without any explanation!
  • If you wrote the program before solution is posted, you can show me the resullt and start to write the next program. You don't need to wait for the solution! You can continue with the next program!
  • Please, follow the directions! Keep the names of the files according to the directions! Make sure that you are in the right directory!
    Part I: Practice Part
    1. Login to the system using your login name and the password
    2. Change to your CSCI151 directory: cd CSCI151
    3. Create a new directory lab2 under your CSCI151 directory: mkdir lab2. All program that you will write in the Pratice Part will be saved in the directory lab2 .
    4. Program 1 :
      • Open emacs by typing the following at the LINUX prompt
        emacs Average.c &
        Average.c is the name of the file.
        Remember that C program file name should end with an extension .c
      • In the file Average.c you will write a C program that prompts the user to enter three integers, read an input into a variables num1, num2, and num3 of type int. Use one scanf statement to do this. The program will calculate the average of the input numbers. Since, we are working with the integers your average will be the integer part of the real average value. You don't need to use decimal point arithmetics in this program. The output of the program will include: your full name, the values of the input numbers and the calculated average with the appropriate message. Print your name, input numbers and the result on separate lines (the output will consist of three lines). For example, if the input was 1, 2 and 4. The output should be (PAY ATTENTION: instead of Yana Kortsarts you have to print YOUR name):


        My name is Yana Kortsarts
        Input numbers are: 1, 2, and 4
        The integer part of the average of the input numbers is 2

      • Compile your program using the descriptive name for the executable file,
        type: gcc -o Average Average.c
        Average is the name of the executable file. In order to run (execute) your program you will need to type Average at the LINUX prompt.
      • Run your program a few times with different inputs, type: Average at the LINUX prompt.
      • Show me the result
    5. Program 2
      • Open emacs by typing the following at the LINUX prompt
        emacs dollar.c &
        dollar.c is the name of the file.
      • In the file dollar.c you will write a C program that prompts the user to the nonnegative integer that will indicate the amount of dollars that user has and prompt to the positive integer that will indicate the valid dollar bill value. The program will calculate the exact amount of bills in the total amount. Suppose the user will use all these bills, how much money will be left? Your program suppose to calculate this value also. For example, if the amount of dollars that user has is 123 and the bill value is 10 the program shoud produce the following output:

        You have 12 10 dollar bills in 123 dollars
        If you will use 12 ten dollar bills you will have 3 dollars left

      • Compile and run your program before you will practice to do script submission with this program.
      • To compile, type: gcc -o dollarExe dollar.c
      • To run, type: dollarExe
      • Run your program with different inputs.
      • Show me the result

    6. Program 3
      • Write a C program Picture.c that prints your first and last names and a rectangle and a triangle as follows:
        ******
        *        *
        *        *
        *        *
        ******

            *
          ***
        *****
      • Compile and Run your program
      • Show me the result

    7. Program 4:
      • Write a C program that prompt the user to enter one positive 3-digits integer. The program finds and prints the integer part of the average of the digits of the input number. Call your program AveDigits.c For example, if the inputs is 235, the output will be: 3.
    8. DO THE ASSIGNMENT PART!-->

    9. Have a good evening.