CSCI 151: Introduction to Computer Science - Fall
2009
Lab 3
Objectives:
practice with basic LINUX commands,
integer arithmetic
in C;
compiling
and executing C code.
Lab 3 includes Practice Part and Assignment Part.
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:
- Discussion of the program
- Writing the program by yourself
- Writing the solution on the board
Important:
Start your program with comments part that includes:
your first and last names
your e-mail
today's day
the name of the program source file (for example: hello.c)
the short description what this program is doing
list of the variables with the short description
for each variable -
name, type, purpose. This part could be done in the program by adding
comment after each variable declaration.
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
- Login to the system using your
login name and the password
- Change to your CSCI151 directory: cd CSCI151
- Create a new directory lab3 under your CSCI151 directory:
mkdir lab3.
- Change to lab3 directory
cd lab3
- All program that you will write in the Pratice
Part
will be
saved in the directory lab3 .
- Program 1 :
- Open emacs by
typing the following at the LINUX prompt
emacs prodDig.c &
- In the file prodDig.c
write a C program
that prompts the user to enter
one positive 3-digits integer and finds and prints
the product of the digits of the input number.
- After you finished writing , compile and run your program to check
that your program returns a correct output.
Run your program a few times with different inputs to test the corectness
of the output.
- Show me the result
- Program 2:
- Open emacs by typing the
following
at
the LINUX prompt
emacs reverse.c &
- In the file reverse.c
write a C program
that prompts the
user to enter one positive 4-digits integer. The program finds and
prints the everage of the digits and prints the digits of the
input number in
reverse order with the space between digits. For example, if the input is
2348, the output should be:
average of the digits is: 4
the digits in reverse order are: 8 4 3 2.
- Compile and run your program with different inputs
- Show me the result
- DO THE ASSIGNMENT PART!
- Have a good evening.