Introduction to Computer Science - Fall
2009
CSCI 151
Lab 5
Objectives:
practice with basic LINUX commands,
integer and float/double arithmetic
in C, equality and relational operators, if, if else, if else if , and
while statements;
compiling
and executing C code.
There is LAB ASSIGNMENT ONLY TODAY!!!
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 lab5 under your CSCI151 directory:
mkdir lab5
- Change to lab5 directory: cd lab5
- All programs that you will write in this lab you
will save in your lab5 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)
Lab Assignment
- Program 1 (35 points):
- Write a program that converts kilometres to
miles. Use the following $
miles = kilometres * 0.6214
- Compile and run your program
- Show me the result
- Program 2 (35 points)
- There is a treasure chest with 1 million dollars. The chest has a
5-digit
combination lock that opens under the following conditions: the first
digit should be equal to the fifth digit, the second digit should be odd,
and the product of the third and forth digits should be divisible by 7.
Write a program that reads one 5-digit positive integer and checks whether
the input number opens the chest or not. The output should be YES, if the
chest opens, and NO otherwise.
- Compile and run your program
- Show me the result
- Submit the printout of the source file
- Program 3 (30 points)
- Write a program that reads two integers. If both input numbers
are
divisible by 3,
the program prints the average of the input numbers, if both input
numbers are not divisible by 3, the program prints the sum and the
product of the
input numbers, and if one of the input numbers is divisible by 3 and one
is not divisible by 3
the program prints the average of the last digits of the input numbers.
- Compile and run your program
- Show me the result
- Submit the printout of the source file
- Program 4 BONUS (10
points)
- In the file sortThreeNum.c you will write a C program that
prompts the user
to enter three integers, reads input numbers into variables num1, num2,
and num3
of type int.
The program will sort the input numbers and print the input numbers in
the increasing order. You can assume that the input numbers are different.
For example if the input was 4, -9 and 8 the program should output:
-9, 4, 8
For example , if the input was 1, 0, -90 the program should output:
-90, 0, 1
Try to find a most efficient solution.
- Compile and and run your program a few times with different inputs.
- Show me the result of the execution.
- Submit the printout of the source file
- Program 4 BONUS (10 points):
- In the file MinMaxFive.c
write a C program that prompts the
user
to enter five integers, read an input and then determines and prints the
largest
and smallest number in the group.
- Compile and run your program
- Show me the result
- Submit the printout of the source file
Have a good evening.