Introduction to Computer Science - Fall
2009
CSCI 151
Lab 4
Objectives:
practice with basic LINUX commands,
equality and relational operators, if, if else, if else if ,
statements;
compiling
and executing C code.
LAB 4 consists of PRACTICE PART ONLY
Practice PART:
- Login to the system using your
login name and the initial password
- Change to your CSCI151 directory: cd CSCI151
- Create a new directory lab4 under your CSCI151 directory:
mkdir lab4
- Change to lab4 directory: cd lab4
- All programs that you will write in this lab you
will save in your lab4 directory.
Important:
Start each of your programs with comment part that includes:
your first and last names
your e-mail
today's day
the name of the program ( the name of the file)
the short description what this program is doing
list of the variables with the short description for each variable -
name, type, purpose (this information could be written in the declaration of the variable section of your program)
- 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! Be CREATIVE!! Explain, why this output is printed.
- Program 1
- Open
emacs by typing the following at the LINUX prompt
emacs MinMax.c & In the file MinMax.c
write a C program that prompt the
user
to enter
three integers, read an input and then determines and prints the largest
and smallest number among three inputs. The program should print your last
and first names, input numbers, and the minimum and maximum among the input numbers.
- Compile and run your program with different inputs
- Show me the result
- Program 2 :
- Open emacs by
typing the following at the LINUX prompt
emacs digitsGame.c &
- In the file digitsGame.c
write a C program
that prompts the
user to enter one non-negative 4 digits integer.
- The program will do the following: if the input number is even, the
program will print the digits of the number in the reverse order with the
tab space between the digits with appropriate message, and if the nubmer
if odd, the program will
calculate the sum and the product of the digits and prints the result
with the appropriate message.
- Compile and run your program with different inputs
- Show me the result
- Program 3:
- Write a C program that prompts the user
to enter three integers. If the product of the input numbers is larger
than the sum of the input
numbers, your program
prints "Hello" , if the product of the input numbers is equal to the sum
of the input
numbers, your program
prints your name, otherwise your program finds the integer part of
the average of the
input numbers and outputs tne result.
Call you program game.c
- Compile and run your program with different inputs
- Show me the program
- Program 4:
- Open emacs by
typing the following at the LINUX prompt
emacs rightTriangle.c &
rightTriangle.c is the name of the file.
Remember that
a C
program file name should end with an extension .c
- In the file rightTriangle.c you will write a C program that
prompts the
user
to enter three non-zero integers, reads an input in a variables a, b
and c
of type int.
The program will determine and print if the input numbers could be the
sides of a right triangle.
- Compile your program
- Run your program a few times with different inputs
- Show me the program.